Unix scripting: need last (or second last) line before each blank line

Hello again (where would I be without you).

In a file I need last line before each blank, unless last line has regex HOLD in it, then I would need the second last line. See attached screenshot.
Bottomline, I need lines with last runtime of each job.

Thanks for your help.
conman.jpg
WatnogAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
This treats lines with more than 2 columns as non-blank
perl -ane '@F>2||print $l;/HOLD/||($l=$_)' file
0
 
ozoCommented:
perl -ne '/\w/||print $l;/HOLD/||($l=$_)' file
0
 
WatnogAuthor Commented:
Thanks, that's great.
I discover that what I thought to be blank lines fact aren't,  :-~
They would become if I can get rid of the last 2 columns, see attached.
That would make your oneliner work as intended.
Cheers.



conman1.jpg
0
 
WatnogAuthor Commented:
Last 2 columns that is 'Returncode' and 'Dependencies'.
0
 
WatnogAuthor Commented:
Wonderful.
Thx.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.