Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grep once completed then move to another directory

Status
Not open for further replies.
Jun 3, 2007
84
US
Hello, I am trying to write a script to grep through a bunch of file for different words. I am having problems moving the files to another directory once my grep is done processing. How can I tell my script to only move the files once the grep is complete. Example if I am grepping for abc def zzz against a file called test.txt. I first want to ensure that the grep for all three (abc def zzz) is complete before it tries to move the file. How can I force my script to check that the grep command is done running, once it's done running then its ok to move the file?

thanks,

FYI I am just doing a for files in /path/*; do etc...
 
Check for it in the process list using ps. Alternatively, use the $? variable to check for completion.

Sorry I can't expand any more just now as I have to go - perhaps someone could jump in and elaborate (or give better options!).

I want to be good, is that not enough?
 
Just as Ken suggested.
If you are moving files based on grepping for a selection of words then you could use egrep and then use an if statement to check for completion and process the files;
i.e
for files in /path/*; do
egrep "aaa|bbb|ccc" $files > /dev/null
if [ $? = 0 ]; then
< whatever you want to do >
fi
done

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top