Can someone tell me how can we create same xml tag lines based on the number of lines present in other file and replace the Name variable vaule present in other file.
and say I have Namesfile which has 500 names/lines in it, all I need to do is read this file and create the above said xml tag by replacing the value of the Name=
ex : Namefile contains 5 lines
A1
A2
A3
A4
A5
now, once script is run, I should the 5 xml tag lines as output ie,
I tried it by myself, it simple while loop did the trick..
Many Thanks..
#!/usr/bin/bash
while read line
do
#echo "Generating xml tag is :<typ:RequestKey NameType="RIC" Name="A1" Service="DDA"/>"
echo "<typ:RequestKey NameType="RIC" Name="\"$line\"" Service="DDA"/>" >> /tmp/xmlfile
done < /tmp/xmllist
Thanks for sharing, Optimus. Good that you found a solution.
Some remarks:
The shebang ( #! ) should be in the first two positions of the script, there should not be a space in front of it, nor an empty line above it..
The quoting in the echo statement is not right (for example the variable $line is unquoted), it should be:
The second EOF should be at the first position of the line.
instead of redirecting the echo statement and repeatedly appending to a file, you could also redirect the output of the loop. So it becomes:
#!/usr/bin/bash
while read line
do
# echo "Generating xml tag is :<typ:RequestKey NameType="RIC" Name="A1" Service="DDA"/>"
echo "<typ:RequestKey NameType=\"RIC\" Name=\"$line\" Service=\"DDA\"/>"
done < /tmp/xmllist > /tmp/xmlfile