04 Jan, 2007, Aidan wrote in the 1st comment:
Votes: 0
Okay, here's what I'm trying to do, hopefully someone can help.
My knowledge of Linux is limited, though I'm working on fixing that even now.

I want to grep a series of flat-files, (more than 2000) for a specific word.
If that word is found, then I want to move that file to another directory.

I know I need to write a script to do it, but I don't know how.
Any suggestions? :)

Thanks!
04 Jan, 2007, bbailey wrote in the 2nd comment:
Votes: 0
Quote
I want to grep a series of flat-files, (more than 2000) for a specific word.
If that word is found, then I want to move that file to another directory.


This is probably how I'd do it:

find -name "*.txt" -exec grep -s -l wordtosearchfor {} \; | xargs mv -t /path/to/new/dir


That will find all files ending in .txt in the current directory and subdirectories, grep them for "wordtosearchfor", then move each file to /path/to/new/dir if the word was found. Find can be overkill if you have a simple directory structure and don't have any criteria other than the filename for which files you want to grep. As with anything in unix, there's more than one way to do it.
05 Jan, 2007, Aidan wrote in the 3rd comment:
Votes: 0
Here's what happened…

find -name "*" -exec grep -s -l Created {} \; | xargs mv -t ../test
mv: invalid option – t
Try `mv –help' for more information.
mv: invalid option – t
Try `mv –help' for more information.
05 Jan, 2007, bbailey wrote in the 4th comment:
Votes: 0
Quote
find -name "*" -exec grep -s -l Created {} \; | xargs mv -t ../test
mv: invalid option – t
Try `mv –help' for more information.
mv: invalid option – t
Try `mv –help' for more information.


Apparently your mv implementation doesn't support the -t option. 'mv –version' shows my version as "mv (GNU coreutils) 5.96".

An alternate version:

find -name "*" -exec grep -s -l word {} \; | xargs -i mv {} ../test


That can be simplified to:

grep -r -s -l Created * | xargs -i mv {} ../test


Both versions search every file in the current directory and subdirectories, so there's no need to use find when a simple recursive grep will do.
05 Jan, 2007, Aidan wrote in the 5th comment:
Votes: 0
Thanks :) Worked like a champ.
0.0/5