
perldoc perlintro
perl -ne 'print if 1 .. 5' our_file
perl -ne 'print unless 1 .. 5' our_fileThe unless option means not to print lines 1 through 5.
perl -p -i.bkp -e 's/SCO/Satan/' SCO_newsHere, we have substituted the word SCO for the word Satan in the file SCO_news and besides, we have created a backup file. This is a good idea because if we hadn't used the -i.bkp option, we would have overwritten the SCO_news file forever.
ls -l | perl -lane 'print $F[+8]'This will print out just the name of the file. That's not particularly useful because we can do this just as easily by typing ls -1 . But if we add a little pizazz to it, it becomes extremely useful.
ls -l|perl -lane 'print join " ",@F[5..8]'This will print out the month, year and hour of the file's creation or last modification and the file name.
perl -e 'for (@ARGV) { rename , lc() ; }' * All of the files (*) in that particular directory will be renamed to the lowercase equivalent.perl -ne 'push@w,/(b[A-Z]S*?b)/g;END{print"@w"}' perl -ne 'print "$1n" if /sto=<([^>]+)>.*?relay=(?!local,)/' /var/log/mail.logAlone, this is not an effective spam fighting tool, but if you see mail addresses with clear patterns, you may be on to some spam activity.
cat /proc/net/tcp |perl -lane '(undef,)=split ":",; print hex()."t".getpwuid() if '|sort -n|uniq -cThis is tremendously important. Ports that aren't needed should be closed. Any open port is a potential source of unwanted entry. Here we have passed a reading of our TCP ports to Perl and then, as we saw earlier, we sort them and filter out any repeat entries with uniq.
cat access | perl -ne 'print "$1n" if /GET (.*?) HTTP/'|sort|uniq -c|sort -nr|less