I have a large XML file with multiple instances of the string REPLACEME. In a second file, I have a list of strings (which contain commas) such as:
58,-21,0
234,-38,0
I'd like to replace each instance of REPLACEME in the first file with one of the values from the second file, and then move on to the next instance.
I've looked at bash (sed, awk, perl) and Powershell. I've been told I shouldn't use for loops, but use file loops and parse the file back in. So I've tried this:
file2=/file2.txt
while IFS= read -r line; do
printf '%s\n' "$line"
sed '0,/REPLACEME/s//$line/' /file1.xml
done < "$file2"
But it doesn't do anything. Possibly because the XML files have symbols? It doesn't error, it just doesn't do anything.
Happy to ditch my code entirely or switch parsers if I can find something that can achieve the replacement result?
EDIT: Asked for an example of the XML. The XML markup is part of a KML file, the strings are coordinate points. Example below:
<Placemark>
<name>5005</name>
<MultiGeometry>
<Polygon>
-snip-
</Polygon>
<Point>
<gx:drawOrder>1</gx:drawOrder>
<coordinates>REPLACEME</coordinates>
</Point>
</MultiGeometry>
</Placemark>
There are hundreds of such entries in this file, which need to be filled using corresponding coordinates from the list in file2.