Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to print the line matching pattern and a specif line after

Status
Not open for further replies.

cicalons

Technical User
Mar 7, 2005
4
IT
I would like you help in order to achieve this:

I have to print the line matchi pattern and this is OK,but at the same time print
a specific line after: for exmple the third, the fourth etc ..... .

But only the pair of lines above reported:
- the one matching the string
- and jsut the specifi line (3, 4 5 , 6 .....) NOt the other lines between(in teh middle).
Example: I search for "BBBB" string:

AAAA BBBB CCCC DDDD
EEEE FFFF
GGGG HHHH
IIII LLLL MMMM JJJJ

and I want to print this output (considering jus the forth line also the one matching string)
AAAA BBBB CCCC DDDD
IIII LLLL MMMM JJJJ

Thanks a lot in advance.

Ciao
 
What about this ?
Code:
awk '/BBBB/{i=1;print}!i{next}{if(i++==4){print;i=0}}' /path/to/input

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top