From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 26 14:24:18 2007 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8149816A407 for ; Mon, 26 Mar 2007 14:24:18 +0000 (UTC) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (comp.chem.msu.su [158.250.32.97]) by mx1.freebsd.org (Postfix) with ESMTP id DBE6F13C45D for ; Mon, 26 Mar 2007 14:24:17 +0000 (UTC) (envelope-from yar@comp.chem.msu.su) Received: from comp.chem.msu.su (localhost [127.0.0.1]) by comp.chem.msu.su (8.13.4/8.13.4) with ESMTP id l2QDp8Fo086305 for ; Mon, 26 Mar 2007 17:51:08 +0400 (MSD) (envelope-from yar@comp.chem.msu.su) Received: (from yar@localhost) by comp.chem.msu.su (8.13.4/8.13.4/Submit) id l2QDp7MG086304 for hackers@freebsd.org; Mon, 26 Mar 2007 17:51:07 +0400 (MSD) (envelope-from yar) Date: Mon, 26 Mar 2007 17:51:07 +0400 From: Yar Tikhiy To: hackers@freebsd.org Message-ID: <20070326135106.GG60831@comp.chem.msu.su> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.9i Cc: Subject: sed -i X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Mar 2007 14:24:18 -0000 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 %%%%%