One-line global string replace in all files with sed (or awk?)

Miguel Mendez flynn at energyhq.es.eu.org
Wed Jan 26 07:55:37 PST 2005


On Wed, 26 Jan 2005 16:43:25 +0100
Anthony Atkielski <atkielski.anthony at 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


Cheers,
-- 
Miguel Mendez <flynn at energyhq.es.eu.org>
http://www.energyhq.es.eu.org
PGP Key: 0xDC8514F1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20050126/e8dff3f6/attachment.bin


More information about the freebsd-questions mailing list