0

I'm trying to match a line in text files along with +/- 2 lines (above and below) the matched line using Baregrep.

I have looked at several threads on Stackoverflow: here, here and here. However, none of the solutions in these posts have worked for me using Baregrep search.

Say I have the following three lines:

01:51:24:469,   0.000000,   0.000000,  0, -1,000000,0,   0,0,0,9,0, -1,  0, -1,000000,000000,000000,000000,000000,XYZ
01:53:27,           ,           ,   ,   ,      , ,    , , , , ,   ,   ,   ,      ,      ,      ,      ,      ,ABC
01:57:07:308,  43.715645, -79.810035,215, -1,001461,0,   0,0,0,1,2, -1,  4, -1,000000,000000,000000,000000,000000,EFG

My matched line is the middle one (ABC). In addition to ABC, I'd also like to see the top line before it (XYZ) and the bottom one (EFG).

Is there a regex solution which works with Baregrep (specifically) which I can use to look for surrounding context lines of a matched line?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ragzputin
  • 397
  • 3
  • 5
  • 20

0 Answers0