Hi, I was hoping that someone could help me. I have a problem that i am trying to work on and it requires me to change text within multiple files using sed. I use the program to change an occurance of a word throughout different files that are being tested. At first i had to Create a new script, sub2, taking the same three parameters (replacing an occurance of a word in a shell script), that treats the string to be replaced as plain text instead of as a regular expression. I did that and now I have Generalize my sub2 script, producing a new script sub3 that will apply a substitution to any number of files given on the command line. For example
~/UnixCourse/scriptAsst/sub3 foo bar myFile1.txt myFile2.txt
myFile3.txt
should apply the same substitution throughout each of the three files named there.
Here is my code
#!/bin/sh
File1="$3"
File2="$4"
File3="$5"
testNum="$File1"
for file in ~/*
do
echo $testNum
A="$1"
echo $A
B="$2"
C="$3"
echo "$A" | sed -e 's/\([*.[^$]\)/\\\1/g' > temporary
A="`cat 'temporary'`"
rm temporary
echo "$A"
sed "s/$A/$B/g" "$C" > myFile.txt.updated
mv myFile.txt.updated "$C"
cat "$C"
done
---------- Post updated at 06:18 PM ---------- Previous update was at 05:25 PM ----------
I also posted this in the homework section but i haven't got a response so that is why i am posting it here.