Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Jul 2013 08:52:35 +0200
From:      Matthias Apitz <guru@unixarea.de>
To:        Robert Bonomi <bonomi@mail.r-bonomi.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: sed Guru wanted
Message-ID:  <20130713065235.GA1647@La-Habana>
In-Reply-To: <201307121544.r6CFi7EH003683@mail.r-bonomi.com>
References:  <20130712090404.GA9263@sh4-5.1blu.de> <201307121544.r6CFi7EH003683@mail.r-bonomi.com>

next in thread | previous in thread | raw e-mail | index | archive | help
El día Friday, July 12, 2013 a las 10:44:07AM -0500, Robert Bonomi escribió:

> > I can delete in a text file with
> >
> >  sed '/pattern1/,/pattern2/d' < file
> >
> > all lines between the lines with the given patterns, including themself 
> > also; how could I specify that the deletion should exclude the line with 
> > /pattern1/, i.e. the addr is something like /pattern1/+1 ?
> 
> IF you use ed(1) style commands, then '/pattern1/+1,/pattern2/d' _is_ the
> answer.  <GRIN>
> 
> See: 'man 1 ed', specifically the LINE ADDRSSING section.
> ...

I know, but I wanted it to be a 'one line command' w/o additional script
files; yesterday evening, while sitting in a beergarden, I came up with
the idea to first add one line to the file after the line with pattern1 and
use this new pattern3 for the start of the deletion:

awk -v D=pattern3 '{ print } ; /pattern1/ { print D }' | sed '/pattern3/,/pattern2/d'

Thanks for your thoughts in any case

	matthias
-- 
Matthias Apitz               |  /"\ ASCII Ribbon Campaign: www.asciiribbon.org
E-mail: guru@unixarea.de     |  \ / - No HTML/RTF in E-mail
WWW: http://www.unixarea.de/ |   X  - No proprietary attachments
phone: +49-170-4527211       |  / \ - Respect for open standards



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130713065235.GA1647>