sed behaving strangely when -n and the delete command are combined
Rob Landley
rob at landley.net
Wed Jul 8 10:16:39 UTC 2009
On Tuesday 30 June 2009 07:27:21 Maximilian Gaß wrote:
> Hi,
>
> I have been trying to build eglibc 2.10 on a Busybox-based system. The
> build process is doing some processing with sed, where GNU sed works and
> Busybox sed fails.
>
> I simplified the sed command to the relevant parts:
>
> sed -n -e '1d' -e '1,/@HEADER_ENDS/p' initfini.s
>
> Busybox sed gives no output, while GNU sed gives the expected
It's expected?
If you deleted your ending search condition before evaluating it, would you
expect your search to stop? So why do you expect your search to start when
you deleted your starting condition before evaluating it? (I believe that
according to susv3, delete ends evaluation of the sed script and jumps
immediately to the next line. So your second -e doesn't get run for line 1,
therefore it doesn't start the range.)
Looking at other kinds of addresses, if you did:
sed -n -e '1d' -e '/@HEADER_STARTS/,/@HEADER_ENDS/p' initfini.s
And line 1 was "@HEADER_STARTS", would you expect your range to start anyway?
If not, why do you expect a numerical start address to work differently?
> #APP
>
> #include "defs.h"
>
> /*@HEADER_ENDS*/
>
> It works properly when 1 in the second command is changed to 2. I attached
> initfini.s
Ok, let's look at the spec.
According to http://www.opengroup.org/onlinepubs/9699919799/toc.htm
An address is either a decimal number that counts input lines cumulatively
across files, a '$' character that addresses the last line of input, or a
context address (which consists of a BRE, as described in Regular
Expressions in sed , preceded and followed by a delimiter, usually a
<slash>).
An editing command with two addresses shall select the inclusive range from
the first pattern space that matches the first address through the next
pattern space that matches the second. (If the second address is a number
less than or equal to the line number first selected, only one line shall be
selected.) Starting at the first line following the selected range, sed shall
look again for the first address. Thereafter, the process shall be repeated.
d is "Delete the pattern space and start the next cycle".
Deleting the pattern space starts the next cycle, so the first address never
got matched, so the range didn't start...
As far as I can tell, we're in compliance with SUSv4 and your sed command
isn't. (Of course gnu has magic extensions out the wazoo and your program
expects them. I guess what you're asking is "please implement this funky gnu
extension that makes numeric addresses special, even when the ending case is a
regex...)
Rob
--
Latency is more important than throughput. It's that simple. - Linus Torvalds
More information about the busybox
mailing list