Hi friends,
This is my very first post on forum, so kindly excuse if my doubts are found too silly.
I am trying to automate a piece of routine work and this is where I am stuck at the moment-I need to grep a particular ID through a file containing many records(which start with <LRECORD> and end with </LRECORD>), and print only those records which have the matching ID.
As an example, my input file contents are as below:
If the lines between the <LRECORD> </LRECORD> pair is unique you can use the -A and -B option of the grep command. For example in your post the lines b/w the<LRECORD> </LRECORD> pair is 1 so you can use the command:
grep 'f42' ./input.txt -A 2 -B 1
My awk version is: mawk 1.3.3 (default on Debian Lenny). I also tested with gawk 3.1.5 and both your solution and mine work ^^
What's your awk version and what was the error message ? Maybe I can avoid it next time. Thankssss