Artificial intelligent assistant

inserting timestamps from one file into another I have two files. One, called `file.gpx`, is a list of trackpoints, each of which consists of three lines: <trkpt...> <ele>...</ele> </trkpt> The other, called `times.txt`, is a list of separate lines, each of which looks like this: <time>...</time> What I need to do is insert each `<time>...</time>` line from times.txt into file.gpx so that all trackpoints in file.gpx look like this: <trkpt...> <ele>...</ele> <time>...</time> </trkpt> I was wondering how to achieve this. (The `...` represent different values, irrelevant for the purpose of my question.) Thank you very much for your help.

Using `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>/{ # if record matches...
print t[++idx2] # print array value at `idx2` (pre-incremented)
}
' times.txt file.gpx > new.gpx

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy e7584cfa05f4938f56885ab4e8c257b6