Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Dec 2004 12:50:08 -0600
From:      "antenneX" <antennex@swbell.net>
To:        "Nathan Kinkade" <nkinkade@ub.edu.bz>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Find & Replace string
Message-ID:  <01cb01c4de1f$e8dbae00$0200000a@SAGEAME>
References:  <019101c4de0e$dbdeb2d0$0200000a@SAGEAME> <20041209181336.GA3650@gentoo-npk.bmp.ub>

next in thread | previous in thread | raw e-mail | index | archive | help
From: "Nathan Kinkade" <nkinkade@ub.edu.bz>
To: "antenneX" <antennex@swbell.net>
Cc: <freebsd-questions@freebsd.org>
Sent: Thursday, December 09, 2004 12:13 PM
Subject: Re: Find & Replace string

> In a website of 1.GB+ with several hundred thousand files, I need to
> interrogate all files to replace a single string like "oldone.010"
with
> "newone.011"
>
> What's the best way to do this?
>
> Thanks in advance!
>
> Best regards,
>
> Jack L. Stone

Are you talking about changing the name of the file itself, or a string
within the file?  If it's the former then a shell for loop work.  Maybe
something like:

$ for file in $(find /somedir -name "*.010"); \
 do mv $file $(echo $file | sed -e 's/oldone/newone'); \
 done

If the latter, then using perl, perhaps with the -e -i switches, might
work well.  man perlrun(1) for some tips.

Nathan

-------------------------------------------------------------

No, I want to interrogate several hundred thousand files throughout
several thousand directories to find/replace a single string within each
file found. The string may appear more than once in a file.

Thanks for the reply....




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?01cb01c4de1f$e8dbae00$0200000a>