SED;find and replace;help required
I wrote a script to replace "old_var" by "new_var" in all files in the current directory.
Now, what i wanted was the script reads a lsit of "old_var" and "new_var" from an input file
for eg: the input file is old_new.txt contains
a1 a2
b1 b2
c1 c2......
Here is my script
-------------------------------------------------------
#!/bin/bash
while read old_var new_var line
do
for file in $(grep -l $old_var *)
do
sed -e "s|$old_var|$new_var|g" $file > temp.c
mv -f temp.c $file
echo "Replaced $old_var in file $file"
done
done < $1
---------------------------------------------------------
the problem is say i want to replace PROG with J_E_PROG. normally, it will replace properly in all files.
but when it finds something like C_PROG_DEF, it will replace PROG in this also making it as C_J_E_PROG_DEF .
i don't want this C_PROG_DEF => C_J_E_PROG_DEF conversion.
Can i avoid it? how do i do that? I want only complete word replacement
please help.
Thanks in advance
Gauri
|