From owner-freebsd-questions@FreeBSD.ORG Wed Nov 9 10:30:32 2011 Return-Path: Delivered-To: FreeBSD-Questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 48680106566B for ; Wed, 9 Nov 2011 10:30:32 +0000 (UTC) (envelope-from vince@unsane.co.uk) Received: from unsane.co.uk (unsane-pt.tunnel.tserv5.lon1.ipv6.he.net [IPv6:2001:470:1f08:110::2]) by mx1.freebsd.org (Postfix) with ESMTP id D321F8FC15 for ; Wed, 9 Nov 2011 10:30:31 +0000 (UTC) Received: from vhoffman.lon.namesco.net (lon.namesco.net [195.7.254.102]) (authenticated bits=0) by unsane.co.uk (8.14.4/8.14.4) with ESMTP id pA9AUUJF083252 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO) for ; Wed, 9 Nov 2011 10:30:30 GMT (envelope-from vince@unsane.co.uk) Message-ID: <4EBA5646.5030102@unsane.co.uk> Date: Wed, 09 Nov 2011 10:30:30 +0000 From: Vincent Hoffman User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: "FreeBSD-Questions@freebsd.org" X-Enigmail-Version: 1.3.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Subject: sed vs gnu sed X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Nov 2011 10:30:32 -0000 '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. "