I have a large file that has some regular pattern
snaps1: Counter: 4966 Opens: Counter: 357283 Instance: s.1.aps.userDatabase.mount275668.attributes snaps1: Counter: 0 Opens: Counter: 357283 Instance: s.1.aps.userDatabase.test.attributes
These line are repeated among other lines above and below. I need to print the snaps1 line and also get the instance: line So I need to search for snaps1 but only if counter is greater than 0 and then print snaps1 line and also the instance line.
Sorry have no clue on how to do this? Can you help?
So from the lines above I should see this output
snaps1: Counter: 4966 Instance: s.1.aps.userDatabase.mount275668.attributes
Appreciate any help you can provide
Advertisement
Answer
$ awk '/snaps1/{s=$0; c=$NF} /Instance/ && c{print s ORS $0}' file snaps1: Counter: 4966 Instance: s.1.aps.userDatabase.mount275668.attributes