You're replying to a comment by Erik.

Erik Permalink
July 29, 2009, 17:15

This is one that was driving me crazy - couldn't find it anywhere on the net:

DELETE ALL LINES BETWEEN TWO MARKER PATTERNS (but not the markers themselves):

e.g. in a hosts file

== /etc/hosts ==

192.168.1.2 host1
192.168.1.3 host2

### START ###
#delete
192.168.1.4 host3 #delete
192.168.1.5 host4 #delete
#delete
### END ###

192.168.1.6 host5

=============================

The money:

sed -i -e '1,/^### START ###/!{ /^### END ###/,/^### START ###/!d; }' /etc/hosts

I have no idea how it works, but it does. Now your markers are preserved for you to insert other stuff with your funky automation scripts.

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

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

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