I have a hostnames file which has:
$ cat hostnames.txt
serverxx1
serverxx2
serverxx3
My script:
#!/bin/sh
fileA=build.xml
for i in ./hostnames.txt ; do
sed 's/createConfig machine="Machine"/createConfig machine=" '$i' "/g' "$fileA" > ./tmpfile
done
FileA has:
createConfig machine="Machine"
Output should have FileA:
createConfig machine="serverxx1"
createConfig machine="serverxx2"
createConfig machine="serverxx3"
But I am getting error as
sed: -e expression #1, char 58: Unknown option to `s'
If I change '$i' to just $i , it's replacing Machine with $i not it's value.
Can somebody please help me - if I am using the sed/for properly?
To achieve your target,I recommend you to generate dynamically the file build.xml instead of using replacing parameters:
#!/bin/sh
fileA=build.xml
if [[ -f $fileA ]] ; then
\rm $fileA
fi
for line in `cat hostnames.txt`
do
echo "createConfig machine=\"$line\"" >> $fileA
done
After running this script ,build.xml is created and its content is:
Now the build.xml only has these values. My original build.xml has other stuff above and below it.
What I need is it has to replace the line
createConfig machine="Machine"
with
createConfig machine="serverxx1"
createConfig machine="serverxx2"
createConfig machine="serverxx3"