You're viewing a comment by Peter Krumins and its responses.

October 28, 2011, 08:27

Here is how:

awk -vp=1 '/ABC/,/DEF/ { p=0; if (/ABC/ || /DEF/) p=1 } p'

The -vp=1 sets variable p (p for print) to 1 before the awk script starts.

If the range /ABC/,/DEF/ is matched, then set p to 0 (don't print). However if it's the /ABC/ or /DEF/, then set p to 1 (print).

Then evaluate p. If it's true, awk prints the current line.

Comment Responses

Bhupender Permalink
October 28, 2011, 11:29

Hi Peter,
The sequence of commands you mentioned are extremely smart(and are working fine). I can also mange to get the same output but may be with the help of 10-15 lines. And you did in just one line. Great!!
Thanks You very much.

November 07, 2011, 17:29

You're very welcome!

Reply To This Comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the word "rocket_257": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.