[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: script copy files based upon content



On 8/5/05, Michael Martinell <mike@dakotasioux.com> wrote:
> 
> 
> I am trying to figure out how to come up with a shell script that will cat
> or grep a file and if it contains the word SPAM it will then move it to
> another folder.
> 
> I have been trying combinations of grep SPAM * | mv * ../spam however I
> don't know what to put in for * since the filenames are always changing.
> 
> I am guessing that I need to create an array by doing something with ls,
> however I am having trouble puzzling this one out.
> 
> This job would then run out of cron.

Try this:
find -exec grep -l SPAM {} + | xargs -I mv {} ../spam
If the filenames can have spaces in them:
find -exec grep -l SPAM {} + | tr " " "\0" | xargs -0 -I mv {} ../spam



Reply to: