Link to home
Start Free TrialLog in
Avatar of Watnog
WatnogFlag for Belgium

asked on

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
Avatar of ozo
ozo
Flag of United States of America image

perl -ne '/\w/||print $l;/HOLD/||($l=$_)' file
Avatar of Watnog

ASKER

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
Avatar of Watnog

ASKER

Last 2 columns that is 'Returncode' and 'Dependencies'.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Watnog

ASKER

Wonderful.
Thx.