I have return files from a process that has then original input record followed on the next line by a response record..either AA,........... for accepted or EE,.......... for errored.
i.e
11,new,123
AA,accepted
12,exist,443
EE,rejected
13,old,223
AA,accepted
I want to write a small script that will return the row and it's response to a separate file.
I.e. I tell the script I want the records that start 11 and their responses and I get the first two lines above. I can do the pattern matching etc to get the first line - but I am having trouble getting the second line to come back too.
Could you use the -n option of grep to get the line numbers & use awk with {FS=":"} {print $1} to chop them out into a temporary file.
You can then run down the input file again with this file of line numbers & extract the line & the line after each time.
Might take some time to run though.
How about:
sed -n '/^11/{;p;n;p;q;}'
This assumes that want only the first couplet that starts with 11. To get them all, omit "q;".
Thanks guys....
I like the sed option...but I think I found the same in awk.....
awk -F"," ' /^11/ { print ; getline; print } ' my_file
Cheers for your help.
Just to mix things up a little:
If you have GNU grep, you could do this:
grep -A1 "^11" your_file