Re: How to get next line of grep-matched line (806 Views)
Reply
Advisor
mura-kei7
Posts: 27
Registered: ‎07-03-2011
Message 1 of 4 (834 Views)

How to get next line of grep-matched line

Hi,

Does anyone know how to display next line of grep-matched line?

grep command does not have -A parameter???

I need cluster package name and status, but don't know its name, status, node...

So, I want to get 2 lines from output of following cmviewcl -v .

    PACKAGE        STATUS        STATE         AUTO_RUN     NODE        <--this line and
    mypackage      up              running       enabled      mynode       <--this line

 

 

 

 

Acclaimed Contributor
Dennis Handly
Posts: 25,274
Registered: ‎03-06-2006
Message 2 of 4 (829 Views)

Re: How to get next line of grep-matched line

[ Edited ]

gnu grep has a -A1 option to get the next line.

 

Or you can use sed or awk to find then print the next line.

awk '

/PACKAGE/ {

   print $0

   getline

   print $0

}' file

Honored Contributor
Matti_Kurkela
Posts: 6,271
Registered: ‎12-02-2001
Message 3 of 4 (813 Views)

Re: How to get next line of grep-matched line

Yes, GNU grep has the -A option, but HP-UX standard grep does not have it.

 

Which version of Serviceguard are you talking about?

 

At least on Serviceguard A.11.17 and newer, you can get the output in a different, machine-parseable format:

cmviewcl -f line -v

 This output format might be easier to use in your own scripts.

MK
Honored Contributor
Steven Schweda
Posts: 9,096
Registered: ‎02-23-2005
Message 4 of 4 (806 Views)

Re: How to get next line of grep-matched line

> Yes, GNU grep has the -A option, but HP-UX standard grep does not have it.

 

Yes, HP-UX standard grep does not have it, but GNU grep is available for HP-UX.

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.