我有两个文件。一个叫做file.gpx
,是一个轨迹点列表,每个轨迹点由三行组成:
<trkpt...>
<ele>...</ele>
</trkpt>
另一个叫做times.txt
,是一个单独行的列表,每一行看起来像这样:
<time>...</time>
我需要做的是将<time>...</time>
times.txt 中的每一行插入到 file.gpx 中,以便 file.gpx 中的所有轨迹点如下所示:
<trkpt...>
<ele>...</ele>
<time>...</time>
</trkpt>
我想知道如何实现这一目标。
(...
代表不同的值,与我的问题无关。)
非常感谢您的帮助。
使用awk
:
awk '
FNR==NR{ # if this is the first input file...
t[++idx]=$0 # save record in array `t` at index `idx` (pre-incremented)
next # continue with next record
}
1 # print record of second input file
/<ele>.*<\/ele>/{ # if record matches...
print t[++idx2] # print array value at `idx2` (pre-incremented)
}
' times.txt file.gpx > new.gpx
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句