You're viewing a comment by Bhupender and its responses.
You're viewing a comment by Bhupender and its responses.
I am being sponsored by Syntress since 2007! They bought me an amazing dedicated server to run catonmat on. If you're looking web services in Chicago area, I highly recommend the Syntress guys!
I love to read science books. They make my day and I get ideas for awesome blog posts, such as Busy Beaver, On Functors, Recursive Regular Expressions and many others.
Take a look at my
Amazon wish list, if you're curious about what I have planned reading next, and want to surprise me. :)


Hi Peteris,
Could you please tell some short command to delete lines from a file between two specific patterns/strings.
I am using the command : cat File | sed '/ABC/,/DEF/ d'
By using above command I am able to delete all the lines between ABC and DEF. But at the same time the first line containing ABC and last lilne containg DEF also get deleted, which i dont want.
Kindly help.
Comment Responses
Here is how:
awk -vp=1 '/ABC/,/DEF/ { p=0; if (/ABC/ || /DEF/) p=1 } p'The
-vp=1sets variablep(p for print) to1before the awk script starts.If the range
/ABC/,/DEF/is matched, then setpto0(don't print). However if it's the/ABC/or/DEF/, then setpto1(print).Then evaluate
p. If it's true, awk prints the current line.Hi Peteris,
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.
You're very welcome!
Reply To This Comment