提炼使用 shell 工具从 KML 获取坐标

提炼使用 shell 工具从 KML 获取坐标
<?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" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
<Document>
    <name>Test.kmz</name>
    <Placemark>
        <name>Test</name>
        <LookAt>
            <longitude>48.7893522149238</longitude>
            <latitude>35.11072013511394</latitude>
            <altitude>0</altitude>
            <heading>-0.1257146222858709</heading>
            <tilt>27.02159138599089</tilt>
            <range>804.546845381412</range>
            <gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
        </LookAt>
        <styleUrl>#m_ylw-pushpin160</styleUrl>
        <Point>
            <gx:drawOrder>1</gx:drawOrder>
            <coordinates>48.78741496263481,35.11017636516465,0</coordinates>
        </Point>
    </Placemark>
</Document>
</kml>

我想48.78741496263481,35.11017636516465从 KML 中提取(但以相反的顺序)作为35.11017636516465,48.78741496263481.这是 sed 或 awk 的任务吗?

提前致谢。

答案1

使用 AWK:

awk -F '[>,]' '/coordinates/ {print $3","$2}' file
  • 寻找模式坐标并打印第三个字段和第二个字段。

答案2

awk -F"[<>]" '/longitude/{long=$3}/latitude/{print $3","long}' file.txt

相关内容