diff options
author | Erich Eckner <git@eckner.net> | 2020-01-14 15:43:37 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2020-01-14 15:43:37 +0100 |
commit | 73444ead611a4fc308c783c4410c8220902bdc51 (patch) | |
tree | a268dcf8ba8f4cea6e64d1193fb2d70762277781 | |
download | gpx-statistics-73444ead611a4fc308c783c4410c8220902bdc51.tar.xz |
Initial commit
-rwxr-xr-x | gpx-to-tsv | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/gpx-to-tsv b/gpx-to-tsv new file mode 100755 index 0000000..22e6627 --- /dev/null +++ b/gpx-to-tsv @@ -0,0 +1,38 @@ +#!/bin/sh + +start=$(date +%s) + +sed ' + s/>/\0\n/g + s/</\n\0/g +' \ +| grep -vxF '' \ +| sed -n ' + /^<gpx[[:space:]>]/,/^<\/gpx>$/ { + /^<gpx[[:space:]>]/ d + /^<\/gpx>$/ d + p + } +' \ +| tr -d '\n' \ +| sed ' + s@<trkpt @\n\0@g + s@</trkpt>@\0\n@g +' \ +| grep -vxF '' \ +| sed ' + 1 { + \@^<metadata>.*</metadata><trk>.*<trkseg>$@ d + } + s@^<trkpt lat="\([-0-9.]\+\)" lon="\([-0-9.]\+\)"><ele>\([-0-9.]\+\)</ele><time>\([0-9]\{4\}\(-[0-9]\{2\}\)\{2\}T[0-9]\{2\}\(:[0-9]\{2\}\)\{2\}Z\)</time></trkpt>$@\1\t\2\t\3\t\4@ + t + \@^</trkseg><trkseg>$@ d + \@^</trkseg></trk>$@ d + w /dev/stderr +' \ +| while read -r lat lon ele time; do + printf '%s\t' "${lat}" "${lon}" "${ele}" + date -d"${time}" +%s +done + +echo $(($(date +%s)-start)) |