search - Searching and printing sections of file -


i have file in following format-

----------------------- key1 = val11 key2 = val21 key3 = val31 ----------------------- key1 = val12 key2 = val22 key3 = val32 ------------------------ 

i need query giving "key2=val22", , print complete section (key1, key2, key3) of matching block.

one of possible ways using csplit:

csplit -s --prefix=mytempfile testfile '/-----------------------/+0' "{*}" \     && cat `grep -l 'key2.*=.*val22' mytempfile*` && rm mytempfile*  ----------------------- key1 = val12 key2 = val22 key3 = val32