deleting texts between patterns

John Savage rookswood at suburbian.com.au
Sat May 20 05:53:17 CEST 2006


Tim Chase <python.list at tim.thechases.com> writes:
>> I wish to delete lines that are in between 'abc' and
>> 'xyz' and print the rest of the lines. Which is the best
>> way to do it?
>
>        sed -n -e'1,/abc/p' -e'/xyz/,$p' file.txt
>
>which is pretty straight-forward.

While it looks neat, it will not work when /abc/ matches line 1.
Non-standard versions of sed, e.g., GNU, allow you to use 0,/abc/
to neatly step around this nuisance; but for standard sed you'll
need a more complicated sed script.
--
John Savage                   (my news address is not valid for email)




More information about the Python-list mailing list