Rob Dixon wrote:
On 13/02/2012 22:28, Harry Putnam wrote:
I found some one liners on this web page:

http://www.techrepublic.com/article/use-command-line-perl-to-make-unix-administration-easier/1044668


This one appears not to work at all. Can anyone say why that is? Is
it just too old?

From the cited page:
,----
| The command provided using the -e option is executed on each line, but
| if you'd rather have word-level granularity you can add the a,
| auto-split option. When used with p, the -a option causes Perl to
| break each input line on white space into the array @F as if it were
| passed through Perl's split command. This option can be used to easily
| work with columnar data. A script like:
`----
perl -i -n -a -e 'print @F[2,4];' mychart

I tried to use it exactly as shown by first getting a few lines of
columnar data from ping:

ping 8.8.8.8>|tee ping.lst
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_req=1 ttl=53 time=8.52 ms
64 bytes from 8.8.8.8: icmp_req=2 ttl=53 time=9.88 ms
64 bytes from 8.8.8.8: icmp_req=3 ttl=53 time=12.3 ms
^c

And then (trying to print just the time column
perl -i -n -a -e 'print @F[6];' ping.lst

But there is no output at all.

The -i option calls for in-place editing, where the output from Perl
replaces the input file. Take a look at ping.lst and you should find
your output. If you want to see the output on the console, just remove
-i and, if you would prefer to see each item on a separate line, add -l
like this

perl -l -n -a -e 'print @F[6]' ping.lst

Usually written as:

perl -lnae'print $F[6]' ping.lst



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to