Search for an expression and capture few lines above & below it (399 Views)
Reply
Occasional Contributor
rk_12345
Posts: 4
Registered: ‎08-30-2011
Message 1 of 3 (399 Views)
Accepted Solution

Search for an expression and capture few lines above & below it

Hi All,

 

I have a file..my aim is to:

1. Search for the line containing a particular expression

2. Grab 3 lines above that expression

3. Grab 5 lines below that expression

 

Please let me know how can this be achieved?

 

Many a thanks..

Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 3 (397 Views)

Re: Search for an expression and capture few lines above & below it

Hi:

 

You can roll your own or you can use a GNU 'grep'.  See here for some ways to build your own:

 

http://h30499.www3.hp.com/t5/System-Administration/grep-for-string-but-include-lines-above-and-below...

 

See here for a GNU 'grep':

 

http://hpux.connect.org.uk/hppd/hpux/Gnu/grep-2.9/

 

If you chose to use the Porting Centre's offering, be sure to install the dependencies.  This is easily done by first installing the 'depothelper' from there.

 

Regards!

 

...JRF...

Please use plain text.
Occasional Contributor
rk_12345
Posts: 4
Registered: ‎08-30-2011
Message 3 of 3 (371 Views)

Re: Search for an expression and capture few lines above & below it

Thanks James...I tried a script find_before_after...works good.

Also installed the GNU grep and its dependencies. That works like wow..
Please use plain text.
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