Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Jan 2005 20:13:56 +0200
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Miguel Mendez <flynn@energyhq.es.eu.org>
Cc:        atkielski.anthony@wanadoo.fr
Subject:   Re: One-line global string replace in all files with sed (or awk?)
Message-ID:  <20050126181356.GA6596@orion.daedalusnetworks.priv>
In-Reply-To: <20050126165505.06d2b3d4.flynn@energyhq.es.eu.org>
References:  <1878149195.20050126164325@wanadoo.fr> <20050126165505.06d2b3d4.flynn@energyhq.es.eu.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-01-26 16:55, Miguel Mendez <flynn@energyhq.es.eu.org> wrote:
> On Wed, 26 Jan 2005 16:43:25 +0100
> Anthony Atkielski <atkielski.anthony@wanadoo.fr> wrote:
>> A few years ago, I'm sure I came across a one-line way of replacing
>> every occurence of one string with another in an entire directory of
>> files (potentially including all subdirectories as well).  I think it
>> used sed or awk.  Now I can't find it.  The examples on the Web are all
>> multiline scripts or programs, but I'm sure I saw a way to do it all on
>> just one line.
>>
>> Can anyone tell me how to do this?
>
> How about something like this (sh style)...
>
> for i in `find . -type f`; do sed -i -e 's/string1/string2/g' $i; done

Nope.  This will potentially overflow the command line limit of some
shells and fail.  The best way I know is to use find/xargs/sed:

	find . -type f | xargs sed -i '' -e 's/foo/bar/g'



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