|
- No need to put Perl commands in a script before running them.
Write quick Perl scripts on the command line, possibly inside
backquotes (`...`).
- Example: search all files, show lines containing
cat and dog and bird:
% perl -ne 'print if /cat/ && /dog/ && /bird/' *
The dog ate the cat, which had eaten the bird.
The birds flew away from the dogged cat.
- Example: print all those files (use command substitution):
% lpr `perl -ln0e 'print $ARGV if /cat/ && /dog/ && /bird/' *`
- Other UNIX text processing utilities
(sed, awk, etc.) work the same way.
What do the following examples do?
- ls -l | awk '{print $1, $8}'
- ls | sed "s@^@`pwd`@"
- sed G report | lpr
- sed 'G;G' report | lpr
- perl -pe 'print "\n\n"' report | lpr
|