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