Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 4 Sep 2004 02:46:33 +0300
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        jd <web@3dresearch.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: String replacement with sed
Message-ID:  <20040903234633.GA25378@gothmog.gr>
In-Reply-To: <20040903233708.B45BD328AD@smtp.3dresearch.com>
References:  <20040903233708.B45BD328AD@smtp.3dresearch.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2004-09-03 19:37, jd <web@3dresearch.com> 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
$



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