Print lines between two patterns , the awk way …

Beautiful display of AWK craftsmanship. Dont miss the solutions in the comments section.


Note: My awk guide.

Example input file:

The standard way ..


Self-explained indented code:

The first optimization is to get rid of the print , in awk when a condition is true print is the default action , so when the flag is true the line is going to be echoed.

To delete de NEXT statement , in order o prevent printing the TAG line,  we need to activate the flag after the “OUTPUT” pattern discovery and after the flag evaluation.

A slight variation of the program flow and we’re done:

PD: What if we only want to print the lines enclosed between the OUTPUT && END tags ? check this

View original post


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s