From: Brian Foster (blf at domain utvinternet.ie)
Date: Mon 10 Jun 2002 - 16:59:08 IST
| Date: Mon, 10 Jun 2002 14:22:18 +0100
| From: Stephen Shirley <diamond at domain skynet.ie>
|
| On Mon, Jun 10, 2002 at 12:57:06PM +0100, Brian Foster wrote:
| > this is trivial to un-install --- just delete all lines
| > between (and including) the two magic marker lines.
| > numerous tools can do this, sed(1) is perhaps a good choice.
|
| I'm just wondering, could you give a snippet of sed code to demonstrate
| this? I've used sed for line editing lots of times, but anything more
| complex, and the man page maketh no sense to me. I've even tried looking
| for example sed scripts on the sed homepage, but no joy. Therefore, for
| this sort of thing, i'd use sed, cause i know how -)
b.t.w., I'm told O'Reilly's sed & awk book (or is it awk & sed?)
is good .... I cannot vouch for that book myself, as I learned
sed (and awk) the hard way.
the basic sed command in this case is simply:
sed -e 'addr1,addr2 d' ...
i.e., starting with the line identified by <addr1>, delete each
line until (and including) the line identified by <addr2>. for
the solution proposed, addr1 is a bog-simple /^...$/ RE matching
the begin magic marker, and addr2 is a similar RE for the end.
below is a Bourne-ish example, tested with GNU sed 3.02, and
which (AFAIK) will work with any version of any sed anywhere.
=====(cut here and below)=====(sed multi-line delete example)=====(bash script)=====
#!/bin/bash
# the following two sh variables are not strictly necessary.
# they are used only to keep the sed(1)-command readable.
# $begin is an RE matching exactly the first magic marker line;
# and $end is an RE matching exactly the second magic marker.
#
readonly begin='^#BEGIN "example" !DO _NOT_ DELETE THIS LINE!$'
readonly end='^#END "example" !DO _NOT_ DELETE THIS LINE!$'
# this is really just a one-liner sed/shell script:
#
# sed -e '/Begin/,/End/d' ...
#
# which deletes all lines between each and every Begin-End
# pair (inclusive). if there is an End-less Begin, then
# all lines from that End-less Begin to EOF are deleted!
#
sed -e "/$begin/,/$end/d" <<\EOF
here are some lines
to be kept
#BEGIN "example" !DO _NOT_ DELETE THIS LINE!
these lines
are to be removed
#END "example" !DO _NOT_ DELETE THIS LINE!
and these lines
at the end
should also be kept
EOF
=====(cut here and above)=====(sed multi-line delete example)=====(bash script)=====
cheers!
-blf-
--
Innovative, very experienced, Unix and | Brian Foster Dublin, Ireland
Chorus (embedded RTOS) kernel internals | e-mail: blf at domain utvinternet.ie
expert looking for a new position ... | mobile: (+353 or 0)86 854 9268
For a résumé, contact me, or see my website http://www.blf.utvinternet.ie
Stop E$$o (ExxonMobile): «Whatever you do, don't buy Esso --- they
don't give a damn about global warming.» http://www.stopesso.com
Supported by Greenpeace, Friends of the Earth, and numerous others...
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:17:11 GMT