Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

ksh help: list following 3 lines after find a keyword

SOLVED
Go to Solution
Super Advisor

ksh help: list following 3 lines after find a keyword

[ Edited ]

I have a large files, and some lines include a keyword that I am looking for. Further, I wanted to list next 3 lines following the line that  includes the keywork.

 

Thank you very much for your help!

 

 

P.S. This thread has been moved from HP-UX > System Administration o HP-UX > languages. - Hp Forum Moderator

none
3 REPLIES
Acclaimed Contributor Acclaimed Contributor

Re: list following 3 lines after finding a keyword

[ Edited ]

Get yourself gnu grep and just use -A3.

Honored Contributor Honored Contributor

Re: ksh help: list following 3 lines after find a keyword

In case your site doesn't allow open source software outside of hp.com, you can use awk:

 

awk '/pattern/{print;getline;print;getline;print;getline;print}' filename

 

where pattern is whatever keyword(s) you are looking for, and filename is the name of the file.

Acclaimed Contributor Acclaimed Contributor

Re: list following 3 lines after finding a keyword

>In case your site doesn't allow open source software

 

If you like cryptic commands you can use sed:

sed -e '
/pattern/ {
   n; n; n; p
}
d'

Note: sed uses REs and awk uses EREs.