[Sussex] Find & Replace in lots of small files

Nico Kadel-Garcia nkadel at gmail.com
Fri May 18 22:50:52 UTC 2007


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





More information about the Sussex mailing list