What should every Perl hacker know about perl -ne?

2019-03-08 11:18发布

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?

7条回答
混吃等死
2楼-- · 2019-03-08 12:05

My favorite reference for Perl one liners (and the top hit on Google for that phrase) covers perl -ne: http://novosial.org/perl/one-liner/

查看更多
登录 后发表回答