0

I want to use a Regex that find all lines in text except the lines that I passed with Regex. I have found a useful code here enter link description hereawk '/.*test.*/{f=1}f;/end/{f=0}' myFile. I want to use it contrariwise.

I mean I don't want to see the lines between test and end, but I want to see other lines.

I want to do this on a Linux environment.

How can I negative these AWK?

Community
  • 1
  • 1
MSK
  • 159
  • 1
  • 2
  • 7

3 Answers3

1

To see all lines between first and end, inclusive:

awk '/first/,/end/'

To invert that:

awk '/first/,/end/{next}1'

(Slightly more readably, for the second example: awk '/first/,/end/{next}{print}'. The version above depends on awk's default action {print}; 1 is the equivalent of true.)

rici
  • 234,347
  • 28
  • 237
  • 341
0

Some like this

awk '/test/ {f=1} !f; /end/ {f=0}' file

It will print all lines until it find test, then start print again after end is found.

Jotne
  • 40,548
  • 12
  • 51
  • 55
0

sed is more appropriate for this:

sed '/first/,/end/d'

will delete all lines between and including a line matching the pattern first until the first line matching the pattern end.

William Pursell
  • 204,365
  • 48
  • 270
  • 300