grep, maybe

Dan Ritter dsr-mzpnVDyJpH4k7aNtvndDlA at public.gmane.org
Thu Oct 29 11:48:06 EDT 2009


On Thu, Oct 29, 2009 at 11:38:03AM -0400, Maurice wrote:
> Looking for some guidance;
> 
> I have several files within several folders (5 files per folder, and 
> thousands of folders) that I need to search a text file within each 
> folder for a word match (like three_little_pigs.txt, and I need to find 
> "moe", if he's listed) and then when a match is found I need to move 
> (not copy) that entire folder (and it's 3~5 files contained within) to 
> another location...
> 
> I'm thinking grep, but don't know the correct syntax to make all this 
> happen.
> I can easily find all the folders (1949 of them) and the word match 3923 
> times within the text file(s)...


grep -lr STRING | xargs -n1 -I QZQ mv QZQ /path/to/destination/

grep -l means print the filenames where a match is found
     -r means recursively

xargs -n1 means supply one argument per command
      -I QZQ means replace QZQ with the argument

untested, but probably close.


-- 
http://tao.merseine.nu/~dsr/eula.html is hereby incorporated by reference.
You can't defend freedom by getting rid of it.





More information about the Discuss mailing list