Hi I'm having a problem with a sed command that I thought I was using correctly but apparently that's not the case.
I was hoping someone here could point out what it is I am doing wrong?
I am using the print, no print option for a matched pattern in sed. Everything seemed to be working fine except I noticed that some lines that were matching my pattern are missing from my output.
After doing a little digging I found that after the command matched a pattern, if the next line also matched the pattern it would fail to output the second matched pattern line.
Can any one see why its behaving this way?
Below is the command I am using
sed -n -e '/\<PreviousJobNum\>[A-Z]*[0-9][0-9]*[A-Z]*\<\/PreviousJobNum\>/{p;n;}' /MyInputFile > /MyOutPutFile
The file I am reading in is MyInputFile, the content of which is
<PreviousJobNum>93296</PreviousJobNum>
<PreviousJobNum>95879D</PreviousJobNum>
When I run the above command my output in MyOutPutFile is
<PreviousJobNum>93296</PreviousJobNum>
If I change the data slightly in the original MyInputFile to have line between the two matched pattern lines, like below,
<PreviousJobNum>93296</PreviousJobNum>
<PreviousJobNum>95879D</PreviousJobNum>
Then my output Picks up both matched pattern lines in the MyOutPutFile as below.
<PreviousJobNum>93296</PreviousJobNum>
<PreviousJobNum>95879D</PreviousJobNum>
I suppose I could double space my input file to get around this but I think it would be better to understand why its behaving this way?
if anyone was able to offer some assistance with this I would be very grateful.
Thank you very much
Paul