Cultured Perl: One-liners 101

Perl as a command-line utility

Return to article

Listing 12. Renaming JPG files in action
> find . -name "*.jpg" | perl -ne'chomp; $name = $_; $quote = chr(39);s/[$quote\\!]/_/ ; print "mv \"$name\" \"$_\"\n"' > commands

> more commands                         # examine the commands
mv "a.jpg" "a.jpg"
mv "Ha ha.jpg" "Ha_ha.jpg"
...
> source commands                       # one or two errors due to the
                                        # '!' character, fixed by hand

Return to article