[Sussex] Find & Replace in lots of small files
Nico Kadel-Garcia
nkadel at gmail.com
Sat May 19 15:23:20 UTC 2007
Bob Williams wrote:
> On Friday 18 May 2007 23:53:21 Nico Kadel-Garcia wrote:
>
>> Bob Williams wrote:
>>
>>> I have about 3000 shell scripts, each of which contains the same error,
>>> namely a spelling mistake in a path. I am looking for a way to automate
>>> the find and replace I need to do, and wonder if sed is the tool to use?
>>>
>>> I've looked at the manpage, but can't seem to work out how to construct
>>> the necessary lines of instructions - or even if it's possible.
>>>
>>> Can someone advise, please?
>>>
>> There are five million ways to do this
>>
>> sed -i 's/old-text/gnu-text/g' $filename
>>
>> is the key bit.
>>
>> The other useful bit is "grep -rl 'old-text' directory name" to get the
>> list of targets to hit, or maybe something like this.
>>
>> find /dirname -name \*.sh -exec sed -i 's/old-text/new-text/g' {} \;
>> -print
>>
>>
> Many thanks to John, Andy and Nico. sed did the job in the twinkling of an
> eye. I continue to be amazed at the power linux gives back to the user.
>
Oh. Oh, my. I'm glad that worked out for you, but credit where credit is
due: that's an old UNIX command, and part of early GNU work, by the Free
Software Foundation. It's in all the BSD's, all the commercial UNIX's ,
and even in CygWin. Richard Stallman, creator of the Free Software
Foundation, won't do interviews with reporters who won't call it Gnu/Linux.
More information about the Sussex
mailing list