The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 10-13-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,089
search patternA first, when matched, put the $2(assume it contains patternB) in the variable pat, then go through the whole file content and print out all the lines contain patternB


Code:
awk '{
if(index($0,"patternA")!=0)
	pat=$2
arr[NR]=$0
}
END{
for(i in arr)
	if(index(arr[i],pat)!=0)
		print arr[i]
}' filename