[OT] Unix Tools (was: deleting texts between patterns)

Dan Sommers me at privacy.net
Fri May 12 10:07:50 EDT 2006


On Fri, 12 May 2006 07:29:54 -0500,
Tim Chase <python.list at tim.thechases.com> wrote:

>> 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?

> While this *is* the python list, you don't specify whether
> this is the end goal, or whether it's part of a larger
> program. If it *is* the end goal (namely, you just want the
> filtered output someplace), and you're not adverse to using
> other tools, you can do something like

> 	sed -n -e'1,/abc/p' -e'/xyz/,$p' file.txt

Or even

    awk '/abc/,/xyz/' file.txt

Excluding the abc and xyz lines is left as an exercise to the
interested reader.

Regards,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>
"I wish people would die in alphabetical order." -- My wife, the genealogist



More information about the Python-list mailing list