Skip to content
Advertisement

Select first match between two patterns.Restart search if a 3rd pattern is found using sed/awk/grep

I am struggling with the following task(I’ve been searching for answer for a while).

The search is for text between START_PATTERN and END_PATTERN1

Having a file structured like this:

JavaScript

The task would be to restart search if END_PATTERN2 is found. Thus the command output should be:

JavaScript

Thank you for your time!

Advertisement

Answer

this line should work for your example:

JavaScript

test: (I added xx to the expected block lines):

JavaScript

Edit

take only the first match, with awk only:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement