How can I retrieve matches from two repeated patterns: mappedname & its value in the text below?.MapName:abcsomeDiffName=someDiffValuex=3y=6NeedyMappedName=NeedyMappedValue..Flag=truegrep MapName\|NeedyMappedName fileNameIf I run awk on the grep output, it will apply to each line so won't give the expected result.The output I would like to get isabc,NeedyMappedValueIf I run grep MapName\|NeedyMappedName fileName' it will give me the required two lines. And when I extract the required values with awk -F : '{print $2}' it will give abc & I won't be able to extract the second required match, NeedyMappedValue from the filtered grep output. Is there any way to achieve this by running awk with some pattern with a different pattern for second line?
Retrieving two matches from repeated pattern
text processing;grep;awk
I guess that's what you expect:grep MapName\|NeedyMappedName fileName | awk -F: '/MapName/ {printf %s,,$2}/NeedyMappedName/ {gsub(NeedyMappedName=,);printf %s\n,$1}'Edit: removing the unnecessary grep (thanks to Craig Sanders) awk -F: '/MapName/ {printf %s,,$2}/NeedyMappedName/ {gsub(NeedyMappedName=,);printf %s\n,$1}' fileNameand going a little further with awk (nawk on Solaris):awk FS=:|= '/MapName/ {printf %s,,$2}/NeedyMappedName/ {printf %s\n,$2}' fileName