Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete all lines between two patterns 1

Status
Not open for further replies.
Apr 22, 2002
48
US
I am trying to delete lines from a file between a pair of patterns. I know this can be easily done in sed or awk, but I am not getting it today.

Code:
cat file1
something
# BEGIN
to be deleted
this one too
# END
whatever

I want to delete all lines from BEGIN to END, both included.

Any help is appreciated

 
You wanted simply this ?
sed '/BEGIN/,/END/d' /patth/to/input > output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV. Yeah, it was as simple as that. But then there are days. I was doing it with awk and somehow couldn't get it.

Futurelet, awk code gives error for me:

Code:
$ awk '/BEGIN/,/END/{next}1' file
awk: syntax error near line 1
awk: bailing out near line 1
 
Code:
awk '/BEGIN/,/END/{next}1' file
works with awk, gawk, and mawk (I just tested it).
You're probably using something antique and obsolete.

If you have nawk, use it instead of awk because on some systems awk is very old and lacks many useful features. Under Solaris, use /usr/xpg4/bin/awk.
And of course, see if you have gawk or mawk.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top