http://www.perlmonks.org?node_id=764541

Sometimes you have a really repetitive task to do on a bunch of files. Sound familiar? You first need to specify the files, then you need to do the same operation on each one. The shell's traditional pipeline can nicely collect the paths, and then use the perl one-liner to do the operation.

Real life example: I needed to identify all the zipfiles in a directory tree and delete all *.exe files hiding inside the zipfiles.

First collect the files:

du -b */*/old.zip | sort -n | xcol 1 >oldfiles
This shows all the zipfiles that were in subdirectories of subdirectories, then sorts them for size so I can decide to leave out the small ones. xcol is a perl script I posted to Code section to extract the column of filenames to file oldfiles.

Then use this perl one-liner:

perl -e 'while (<>) { chop; system qq{zip -d "$_" "*exe*"} }' oldfiles

Love that Perl!

HTH,
SSF