one liners
remove blank lines:
perl -ni.bak -e 's/^\s*$//' somefile
perl -ni.bak -e 's/^#.*$//' somefile
install some::module
perl -MCPAN -e 'install Some::Module'
Search and Replace:
perl -pi -e 's/change/to this/g' somefile
Find Repeated Lines:
perl -ne 'print if $x{$_}++' somefile
Generate an 8 Letter (Weak) Password:
perl -le 'print map { (a..z)[rand 26] } 1..8'
Find Palindromes:
perl -lne 'print if $_ eq reverse' /usr/dict/words
Strip Most HTML:
cat index.htm | perl -ne 's/\<[^<]*\>//g ;print $_'
Convert File to Lowercase:
perl -ne 'tr/A-Z/a-z/; print' somefile
Add Line to Beginning of File:
perl -0777 -i -ne 'print "first line here\n$_"; somefile
perl -nle 'print $1 while /\<a\b[^\>"]*?\bhref=\"?([^\>"]*)/g' somefile
Remove Duplicate Lines
perl -e '$u=0;while(<>){if(!($s{$_}++)){print $_;$u++}} warn "$u unique of $. total lines.\n"' infile outfile
Available DBI Drivers
perl -e "use DBI; print map qq~$_\n~, DBI->available_drivers;";
Replace Text
perl -i -pe 's/OLD/NEW/g' /path/to/file
digitalcrunch@penguin:~/techgrimoire2/checkpoint-maestro$ find . -name "*.markdown" -exec perl -i -pe 's|permalink: /maestro/|permalink: /checkpoint-maestro/|g' {} +
digitalcrunch@penguin:~/techgrimoire2/checkpoint-maestro$ find . -name "*.markdown" -exec perl -i -pe 's|parent: Maestro|parent: Check Point Maestro|g' {} +