Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 09 Nov 2011 10:30:30 +0000
From:      Vincent Hoffman <vince@unsane.co.uk>
To:        "FreeBSD-Questions@freebsd.org" <FreeBSD-Questions@freebsd.org>
Subject:   sed vs gnu sed
Message-ID:  <4EBA5646.5030102@unsane.co.uk>

next in thread | raw e-mail | index | archive | help
'Hi all,
        I'm trying to move a script from a linux box to a freebsd box.
All going well as its just a bash script and bash is bash, however there
is one line I'm unable to use directly, as bsd sed (correctly according
to SUS at least, I believe[1]) appends a newline when writing to
standard out, gnu sed doesnt. example
BSD
[backup@banshee ~]$ echo -n "/boot:7:1:5; /:7:1:5; /var:7:1:5"  | sed -n
's/[[:space:]]*;[[:space:]]*/;/gp'
/boot:7:1:5;/:7:1:5;/var:7:1:5
[backup@banshee ~]$

LINUX

[backup@amber ~]$ echo -n "/boot:7:1:5; /:7:1:5; /var:7:1:5"  | sed
's/[[:space:]]*;[[:space:]]*/;/g'
/boot:7:1:5;/:7:1:5;/var:7:1:5[backup@amber ~]$

is there any easy way to make our sed do the same as gnu sed here? 
for now I have encapsulated the whole thing in a subshell
[backup@banshee ~]$ echo -n $(echo -n "/boot:7:1:5; /:7:1:5;
/var:7:1:5"  | sed -n 's/[[:space:]]*;[[:space:]]*/;/gp')
/boot:7:1:5;/:7:1:5;/var:7:1:5[backup@banshee ~]$

Which works but seems a little hackish.

Vince

[1]http://pubs.opengroup.org/onlinepubs/007908799/xcu/sed.html
' Whenever the pattern space is written to standard output or a named
file, /sed/ will immediately follow it with a newline character. "




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