linux - How can I grep while avoiding 'Too many arguments' -


this question has answer here:

i trying clean out spam email , ran issue. amount of files in queue, large usual command unable process. give me error many arguments.

i this

grep -i user@domain.com 1us* | awk -f: '{print $1}' | xargs rm 

1us* can between 1us[a-za-z]. thing make work running horrible contraption. 1 file, 1usa, 1usa, 1usb etc, through entire alphabet. know has way run more efficiently.

grep -s $spammer /var/mailcleaner/spool/exim_stage1/input/1usa* | awk -f: '{print $1}' | xargs rm grep -s $spammer /var/mailcleaner/spool/exim_stage1/input/1usa* | awk -f: '{print $1}' | xargs rm 

run several instances of grep. instead of

grep -i user@domain.com 1us* | awk '{...}' | xargs rm 

do

(for in 1us*; grep -li user@domain "$i"; done) | xargs rm 

note -l flag, since want file name of match. both speed grep (terminate on first match) , makes awk script unrequired. improved checking return status of grep , calling rm, not using xargs (xargs fragile, imo). i'll give better version if ask.

hope helps.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -