How to capture this output with perl regex
I have some output in a log file that looks like this:
Quote:
Can anyone show me how to do this? TIA, Pablo |
Does it have to be perl ?
tail - 3 file | head -2 |
Quote:
|
Here's an easy way for you to follow. Since I helped, maybe you could follow-up here and explain how it works so that others can learn too.
perl -e 'undef $/ ; $_ = <> ; @lines = split /-+\n/ ;print $lines[-1]' datafile |
Quote:
I will try to explain what I understand, but I'm no perl guru. Code:
perl -e Code:
undef $/ Code:
$_ = <> Code:
@lines = split /-+\n/ Code:
print @lines[-1] |
Oops on the @lines[-1]. Just checking to see if you were paying attention! ;)
Cheers |
Quote:
perl -e '@a = (1, 2); print @a[-1];' perl -e '@a = (1, 2); print $a[-1];' Also, I tried your suggestion and it worked like a charm - thanks. Slurp then split, that's great. The more I learn about perl the more I like it. Thanks again. |
I tested that it worked, and that's what caused me not to notice my command-line edit typo.
You certainly don't want to be slurping huge files this way, but I supposed your demands weren't that great. Perl is pretty fun. A guy in the Ubuntu forums asked how he could perform some automagic optimization on his assembler code. Some of the responses came back with ungodly solutions. I gave him this: Code:
#!/usr/bin/perl -i.orig |
Re the array v scalar;
yeah, not recommended to use array where you mean scalar, but Perl has a lot of DWIM (Do What I Mean) :) |
All times are GMT -5. The time now is 05:54 AM. |