summaryrefslogtreecommitdiff
path: root/gpx-to-tsv
blob: f93168ddbbc11cc9d6c97aeab4282212ff30d9fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh

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
  \@^</trkseg></trk>.*<trk>.*<trkseg>$@ d
  w /dev/stderr
'