0

I want to catch the output between 2 different patterns, for example :

sed -n '/^pattern1/,/^pattern2/p;/^pattern2/q' 

But I want to catch the output without the patterns in cause.

I know that grep -Ev will help me, but I wonder how it's done with sed.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

1 Answers1

0

You can try using awk:

awk '/^pattern1/{p=1;next}/^pattern2/{p=0}p' file

The variable p is set when the pattern pattern1 is found, and the variable is reset when the second pattern is met.

The p at the end of the script will trigger the default awk action, i.e. print the line if p==1.

oliv
  • 2,636