Solved

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

Posted on 2010-09-16
5
386 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:Watnog
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 33690186
perl -ne '/\w/||print $l;/HOLD/||($l=$_)' file
0
 

Author Comment

by:Watnog
ID: 33690470
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
 

Author Comment

by:Watnog
ID: 33690480
Last 2 columns that is 'Returncode' and 'Dependencies'.
0
 
LVL 84

Accepted Solution

by:
ozo earned 300 total points
ID: 33690540
This treats lines with more than 2 columns as non-blank
perl -ane '@F>2||print $l;/HOLD/||($l=$_)' file
0
 

Author Closing Comment

by:Watnog
ID: 33691002
Wonderful.
Thx.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to pick only current date files from a ftp 14 64
Call Shell Script from Perl Script 6 192
AWS CLI issues with Tags 3 102
change script to get csv file on the prompt 8 24
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question