Sort files with grep

bashgreppipesorting

I have a few hundreds of output files, of which some contain error messages. Lets say I want to automatically put all files containing the string "ERROR_1" in a "subfolder_1", and the rest in a second "subfolder_2". This should be possible by piping grep somehow. What would be a useful syntax?

Best Answer

for a in *;do grep -q ERROR_1 "$a" && mv "$a" subfolder_1 || mv "$a" subfolder_2;done

This should work.

Related Question