The specific task is to use the header of a KML file and insert it into hundreds of split up KML data files that do not have the header.
The KML header is multiple lines and specific spacing. I've found I can use Sed with the 'r' readfile option to grab the contents of a file containing the header. However when I insert the data with '1r' the header is placed in the file starting on the second line. sed doesn't seem to let me address 'line 0' to insert before. Insert mode would work, but I wouldn't be able to just grab the header format that is saved in a file and would need to script the entire header.
#!/bin/bash
for i in ./Split/*;
do sed -i '1r KML_Header.txt' $i
done
The KML Header Looks like this:
<?xml version='1.0' encoding='UTF-8'?>
<kml xmlns='http://www.opengis.net/kml/2.2'xmlns:gx='http://www.google.com/kml/ext/2.2'>
<Document>
<Placemark>
<open>1</open>
<gx:Track>
<altitudeMode>clampToGround</altitudeMode>
The end result with the header will look something like this:
<?xml version='1.0' encoding='UTF-8'?>
<kml xmlns='http://www.opengis.net/kml/2.2'xmlns:gx='http://www.google.com/kml/ext/2.2'>
<Document>
<Placemark>
<open>1</open>
<gx:Track>
<altitudeMode>clampToGround</altitudeMode>
<when>2017-11-16T11:47:52Z</when>
<gx:coord>-97.8216659 30.481537499999998 261</gx:coord>
<when>2017-11-16T11:47:44Z</when>
<gx:coord>-97.8216137 30.481513600000003 259</gx:coord>
<when>2017-11-16T11:45:37Z</when>
<gx:coord>-97.8216659 30.481537499999998 261</gx:coord>
<when>2017-11-16T11:44:54Z</when>
<gx:coord>-97.82162970000002 30.481479699999998 261</gx:coord>
<when>2017-11-16T11:39:55Z</when>
However, this is what my current best command gets me:
<when>2017-11-16T11:47:52Z</when>
<?xml version='1.0' encoding='UTF-8'?>
<kml xmlns='http://www.opengis.net/kml/2.2'xmlns:gx='http://www.google.com/kml/ext/2.2'>
<Document>
<Placemark>
<open>1</open>
<gx:Track>
<altitudeMode>clampToGround</altitudeMode>
<gx:coord>-97.8216659 30.481537499999998 261</gx:coord>
<when>2017-11-16T11:47:44Z</when>
<gx:coord>-97.8216137 30.481513600000003 259</gx:coord>
<when>2017-11-16T11:45:37Z</when>
<gx:coord>-97.8216659 30.481537499999998 261</gx:coord>
<when>2017-11-16T11:44:54Z</when>
<gx:coord>-97.82162970000002 30.481479699999998 261</gx:coord>
<when>2017-11-16T11:39:55Z</when>