DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Mike Whitaker
Mike Whitaker

Posted on

Shell command options you didn't know you needed #5

Technically, this one's a Perl option, but... if your Perl usage is at the sysadmin/devops level (i.e. the Swiss Army Chainsaw) you might find this very handy for processing files and running potentially complex Perl code against every line in the file. Particularly if, like me, you speak better Perl than AWK :D

perl -ne (and perl -pe)

The -ne option wraps the code you provide in the argument with a loop over every line in all the input files, with the line (with trailing CR) stored in $_. The -pe option does the same, but adds an implicit print $_ at the end of the loop.

A couple of trivial examples:

Extract unique IP addresses from your Apache log.

perl -pe 's/^(\d+.\d+.\d+.\d+).*/$1/;' */access.log | sort -u

Poor man's grep with Perl regexes.

perl -ne 'print if /admin\.php/;' access.log

Top comments (0)

DEV has this feature:


Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. 🛠