From owner-freebsd-questions@FreeBSD.ORG Fri Sep 3 23:49:40 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 26D2516A4CE for ; Fri, 3 Sep 2004 23:49:40 +0000 (GMT) Received: from kane.otenet.gr (kane.otenet.gr [195.170.0.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id 16C4D43D2D for ; Fri, 3 Sep 2004 23:48:59 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from gothmog.gr (patr530-b129.otenet.gr [212.205.244.137]) i83NmNBG001203; Sat, 4 Sep 2004 02:48:24 +0300 Received: from gothmog.gr (gothmog [127.0.0.1]) by gothmog.gr (8.13.1/8.13.1) with ESMTP id i83NkYuA025457; Sat, 4 Sep 2004 02:46:34 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from giorgos@localhost) by gothmog.gr (8.13.1/8.13.1/Submit) id i83NkXEF025456; Sat, 4 Sep 2004 02:46:34 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Sat, 4 Sep 2004 02:46:33 +0300 From: Giorgos Keramidas To: jd Message-ID: <20040903234633.GA25378@gothmog.gr> References: <20040903233708.B45BD328AD@smtp.3dresearch.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040903233708.B45BD328AD@smtp.3dresearch.com> Phone: +30-2610-312145 Mobile: +30-6944-116520 cc: freebsd-questions@freebsd.org Subject: Re: String replacement with sed X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Sep 2004 23:49:40 -0000 On 2004-09-03 19:37, jd wrote: > > I need to change a bunch of Analog config files; among other things > change the location of IMAGEDIR. I made this simple script: > > #!/bin/sh > for loop in `ls analog/*` > do > sed -e '/IMAGEDIR/s/www2.3dresearch.com\/analog_images\//fiordiligi.3dresearch.com\/images\//p' $loop > $loop.sed > done > > It works fine, except I get duplicate lines, such as: > > IMAGEDIR http://fiordiligi.3dresearch.com/images/ > IMAGEDIR http://fiordiligi.3dresearch.com/images/ Remove the trailing 'p' from your substitution pattern or use the same regexp with the -n option of sed, i.e.: $ echo foo bar | sed -e '/foo/ s/foo/FOO/p' FOO bar FOO bar $ echo foo bar | sed -n -e '/foo/ s/foo/FOO/p' FOO bar $ echo foo bar | sed -e '/foo/ s/foo/FOO/' FOO bar $