Perl as a command line tool

Perl as a command line tool

Options

 * -e: specify a script right on the command line
 * -p: act as a stream editor similar to sed and awk
 * -n: same as -p but it does not print every line
 * -i: edit in place
 * -i.bak: specify extension for backup file
 * -a: turn on auto split mode
 * -F: specify a new field delimiter (Ex: -F:, or -F/:/, -F/regex/)

Examples
Replace text in a file perl -pe 's/text1/text2/g' outputfile Print 4th word of lines that are not comments perl -naF 'next if /^#/; print "$F[3]\n"' Extract all usernames from /etc/passwd perl -na -F: -e 'print "$F[0]\n"' < /etc/passwd Copy files and rename perl -e 'for(){$a = $_; s/log/log.old/; `cp $a $_`}' Others perldoc -l Net::DNS instmodsh (command line interface) perl -MLWP::UserAgent -le 'print $LWP::UserAgent::VERSION';