Find & Replace string

antenneX antennex at swbell.net
Thu Dec 9 10:50:29 PST 2004


From: "Nathan Kinkade" <nkinkade at ub.edu.bz>
To: "antenneX" <antennex at swbell.net>
Cc: <freebsd-questions at 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....




More information about the freebsd-questions mailing list