Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to do a search using grep inside all the files of a directory for the pattern '@mail.ru>' (to clean up a mess from a spammer). Using Mac OS X's command line, which should be similar to most linux installs, how do I write the command to find all with that pattern, and move it to another directory called 'suspects'? Thanks!

Neil

share|improve this question
add comment

1 Answer

Create the suspects directoy. Then try a command like:

mv $(grep -l '@mail.ru>' *) suspects 

Try the grep command on its own to see what it will find. -l causes grep to list the matching file names. This will only work if there are no spaces in the file names, which should be the case for mail files. Otherwise you should look at using find or changing IFS to exclude spaces while you run the command.

share|improve this answer
    
Useful -- thanks! In the end, I went with this: grep -l -r -i -z '@mail.ru[<>]' 2a | xargs -I{} mv {} 2a-ru where [<>} gave me a choice of < or > at the end of mail.ru (part of identifying the bad mail). And 2a was the folder to be searched, and 2a-ru was for all the mail found to match the pattern. –  Neil Ticktin Mar 22 '12 at 6:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.