sed -i



Hi,

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.

--
Yar

%%%%% sed.t %%%%%
#!/bin/sh

files="1 2 3"
lines="1 2 3 4 5"

makefiles()
{
for f in $files; do
for n in $lines; do
echo $n
done > $f
done
}

echo "### Test 1 ###"
makefiles
sed -i.bak 1,3d $files
tail $files

echo "### Test 2 ###"
makefiles
sed -i.bak /5/,/2/d $files
tail $files

%%%%% output using our sed %%%%%

### Test 1 ###
==> 1 <==
4
5

==> 2 <==
1
2
3
4
5

==> 3 <==
1
2
3
4
5
### Test 2 ###
==> 1 <==
1
2
3
4

==> 2 <==
3
4

==> 3 <==
3
4

%%%%% output using GNU sed %%%%%

### Test 1 ###
==> 1 <==
4
5

==> 2 <==
4
5

==> 3 <==
4
5
### Test 2 ###
==> 1 <==
1
2
3
4

==> 2 <==
1
2
3
4

==> 3 <==
1
2
3
4

%%%%% END %%%%%
_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: $LFN and make
    ... @echo \"$\" not found on path. ... GNU Make version 3.79.2a1, by Richard Stallman and Roland McGrath. ... This is free software; see the source for copying conditions. ...
    (comp.os.msdos.djgpp)
  • Re: bash question ... echo subtleties
    ... echo ignore both these conventions. ... I think it is a POSIX feature. ... intentional and claimed by GNU. ... Note that the Unix spec goes further in ...
    (comp.unix.shell)
  • Re: truncating a variable, sh enviroment
    ... preferably in an sh script or makefile (gnu). ... # echo $FOO ...
    (comp.os.os2.programmer.misc)
  • SUMMARY: KSH day of week script in past
    ... The answer was to use gnu date like so: ... # echo $DAY ... dow() {# year month day ... Get a FREE online computer virus scan from McAfee. ...
    (SunManagers)
  • Re: BSD make vs. GNU make
    ... Because people write more complex makefiles using syntax which is specific to either BSD or GNU make. ... "Features of GNU `make' ... *Note Automatic Variables: Automatic. ...
    (freebsd-questions)