in reply to Printing Last Element of a line using perl memory?
A somewhat different way of doing it:
perl -lne 's[\A\s+][]; s[\s+\Z][]; $last=pop [split /\s+/] if $_; END +{ print $last }' scan.log
- -l auto-chomps
- -n wraps the code in a while(<>){ ... }
- The substitutions remove leading and trailing blanks
- The split extracts the words in the line (whitespace-separated)
- The pop takes the last word
- We save this for each line
- At end of file, we print the current last word, which will be from the last line
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Printing Last Element of a line using perl memory?
by LanX (Saint) on Feb 15, 2013 at 09:42 UTC | |
by pemungkah (Priest) on Mar 11, 2013 at 19:59 UTC | |
by LanX (Saint) on Mar 11, 2013 at 20:09 UTC | |
Re^2: Printing Last Element of a line using perl memory?
by jaredor (Priest) on Feb 15, 2013 at 18:12 UTC | |
by pemungkah (Priest) on Mar 11, 2013 at 20:02 UTC |
In Section
Seekers of Perl Wisdom