Date: Fri, 30 Mar 2007 21:21:33 +0400 From: Yar Tikhiy <yar@comp.chem.msu.su> To: Diomidis Spinellis <dds@aueb.gr> Cc: hackers@freebsd.org Subject: Re: sed -i Message-ID: <20070330172133.GD98431@comp.chem.msu.su> In-Reply-To: <460B76A0.5030200@aueb.gr> References: <20070326135106.GG60831@comp.chem.msu.su> <460B76A0.5030200@aueb.gr>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Mar 29, 2007 at 11:19:44AM +0300, Diomidis Spinellis wrote: > Yar Tikhiy wrote: > > > >Recently noticed that our sed(1) differs from its GNU analog in > >that in -i mode it considers all files as a single sequence of lines > >while the latter treats each file independently. The in-line mode > >isn't in POSIX, so it isn't really clear which way is correct. > > > >Here is a couple of practical consequences: > > > >- our sed won't act on a numeric range of lines in each file, > > as in: sed -i '' 2,5d *, which may be counter-intuitive. > >- our sed's line ranges can span file boundaries in -i mode. > > > >If the second feature isn't important, I think we should use > >a separate line space for each file edited in-line, which is > >usually desired. > > > >Comments? > > > >P.S. Attached are a test script and outputs from it for our > >sed and GNU sed as found in a Linux I have access to. > > > > I believe the GNU interpretation of lines in -i makes sense. Hurray! I've got a blessing from the author of BSD sed himself! :-) Thank you! May I take a bit more of your time? I've started playing with the code and noticed another gray area. Namely a `c' command won't print the text if having 2 addresses with the 2nd address beyond the actual end of file. For example: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% BEGIN $ jot 9 | > sed '6,15c\ > text > ' test 1 2 3 4 5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% END Ditto with RE's, if the 2nd RE doesn't match any line: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% BEGIN $ jot 9 | sed '/6/,/15/c\ > text > ' test 1 2 3 4 5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% END If we've started to delete the pattern space, we should print the text in place of it because `c' is for `change'. BSD and GNU seds have this bug, but Solaris sed doesn't have it. Do you think we should fix it, too? Thanks! -- Yar
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070330172133.GD98431>