Find and replace folder of files with $var

I want to scan through all the files in the folder and replace all instances of $file_X within the file with the variable $X defined in my bash script on my debian 6.0 install.

For example, if the file contains $file_dep I want it to be replaced with the value of the variable $dep defined in my bash script.

Here is an example of my config file:

IP address = $file_dep

Here is an xample of a definition in my bash script

$dep=192.168.0.1

Here is the best starting point I could find using google.

# Replace Config Values
cd /home/config
find . -type f -print0 | xargs -0 sed -i "s/$szAnswer1/$szAnswer2/g"

My pseudo code (im not good with bash)

Find $FILE_X
Replace $FILE_X with value $X

Can anyone offer me a bit more help?

Thanks,

James

This seems a clunky way to go about things, have you considered instead of doing this, simply adding a header/resource file that all of your scripts can source?

$ config.rc
IP_ADDY="10.0.0.10"

and then in any/all of the files:

. /path/to/config.rc

Which will source the profile, and then you could simply replace static defines with the variable name in the file you're sourcing (So that in the future you just have to change it in the one file):

echo "\$dep=192.168.0.1" | sed 's/\(^\$dep=\)\(.*$\)/\1\$IP_ADDY/g'

Here's how I'd do the find statement, with a loop:

for file in $(find /home/config -type f -name -exec ls {} \;); do 
if [ "$(grep -c '^\$dep=' $file)" -gt 0 ]; then
sed 's/\(^\$dep=\)\(.*$\)/\1\$IP_ADDY/g' $file > /tmp/file.out
cp /tmp/file.out $file
fi
done

If you need to or want to add in a line for sourceing a resource file, you could add these before the cp line above (Can do this other ways, this is just an easy way I know):

ed -s  /tmp/file.out << EOF
2i
. /path/to/configrc
.
w
q
EOF