Solved

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

Posted on 2010-09-16
5
378 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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.:

816 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now