Here's what i have so far...
I created a new script, subst2, using three parameters,
1. the string to be replaced ($1)
2. the string with which to replace it ( $2)
3.the name of the file in which to make the substitution ($3)
This performed the substitution and backup file creation when the target string occurs somewhere in the file, but leaves the file completely unchanged if the string being replaced is nowhere in the file.
I got this
if grep "$1" "$3" > /dev/null; then
mv $3 $3.bak
sed "s/$1/$2/g" $3.bak > $3
# grep returned 0, the pattern occurred in at least one line
fi
I got that right but I have a problem with this part right here..
Generalize your subst2 script, producing a new script subst that will apply a substitution to any number of files given on the command line. For example
~/Unix/script/subst foo bar myFile1.txt myFile2.txt myFile3.txt
should apply the same substitution throughout each of the 3 files named there.
I have this code in bash but any code is fine.
2007-08-08
15:32:52
·
1 answers
·
asked by
ddw4e
2