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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find a search pattern within a given pattern

Status
Not open for further replies.

sojankurian

Programmer
Sep 30, 2002
16
US
Hi,
in the sample file given below

line 1
myvar
line 3
FUNCTION
line 5
myvar
line 7
END FUNCTION

I want to print the second 'myvar' which is coming in between FUNCTION......END FUNCTION block.

How do I do it?

Thanks
 
This should do it:

[tt]awk '/^FUNCTION/,/^END FUNCTION/ { if ($0 ~ /myvar/) {print } }'[/tt]

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top