I have been using the Perl command line with a -ne option for years, largely to process text files in ways that sed can’t. Example:
cat in.txt | perl -ne "s/abc/def/; s/fgh/hij/; print;" > out.txt
I have no idea where I learned this, and have only today read perlrun and found there are other forms (perl -pe for example).
What else should I know about perl -ne?
perl -ne 'CODE'is equivalent to the programperl -ane 'CODE'andperl -F/PATTERN/ -aneare also good idioms to know about. They are equivalent toand
Example: advanced grep:
A particularly clever example that uses mismatched braces is here.