![](https://secure.gravatar.com/avatar/35e57997276d9a5890c754c081da50b4.jpg?s=120&d=mm&r=g)
On Thu, Oct 29, 2009 at 12:48 PM, Randall Mason <clashthebunny@gmail.com> wrote:
Sorry, I keep forgetting which email address I signed up with...
I would add quotes and use while, just in case the directory names have spaces and such. "for" splits on any whitespace, which could be quite troublesome.
grep -RFl "moe" somedirectory/ | while read file; do echo mv "`dirname "$file"`" "destination_path"; done
Good suggestion. For this to work, I think you need to add the '-l' (lowercase L) option to grep such that it only prints *names* of files with matching lines instead of every matching line in the file. And, to avoid seeing lots of errors with moving directories with multiple matching files, add a test to the dirname to see that it exists before trying to move it. Something like this: grep -l -RFI "moe" <search-space> | while read file;do dd=`dirname $file`; [ -d $dd ] && mv $dd <destination>;done -BR