Solved

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

687 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