summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2020-01-14 15:43:37 +0100
committerErich Eckner <git@eckner.net>2020-01-14 15:43:37 +0100
commit73444ead611a4fc308c783c4410c8220902bdc51 (patch)
treea268dcf8ba8f4cea6e64d1193fb2d70762277781
downloadgpx-statistics-73444ead611a4fc308c783c4410c8220902bdc51.tar.xz
Initial commit
-rwxr-xr-xgpx-to-tsv38
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))