From 5b693c5af93a6ad9893d7ad52f4204b7b6b7c4db Mon Sep 17 00:00:00 2001 From: rrueger Date: Sun, 18 Jul 2021 23:21:03 +0200 Subject: Add combine-gpx --- combine-gpx | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 combine-gpx diff --git a/combine-gpx b/combine-gpx new file mode 100755 index 0000000..a440e29 --- /dev/null +++ b/combine-gpx @@ -0,0 +1,46 @@ +#!/bin/bash + +combine-gpx.log() { + 1>&2 echo "combine-gpx: $*" +} + +if [[ "$1" =~ ""|-h|--help ]] +then + combine-gpx.log "Combine GPX files (in order) and print to stdout" + combine-gpx.log "Usage: combine-gpx [FILE N ...]" + exit 2 +fi + +USABLE_FILES=() + +for FILE in "$@" +do + if [[ ! -r "$FILE" ]] + then + combine-gpx.log "[WARNING] Cannot read file '$FILE' skipping." + else + USABLE_FILES+=("$FILE") + fi +done + +if ((${#USABLE_FILES[@]} == 0)) +then + combine-gpx.log "[Error] None of the supplied filenames are readable files." + exit 1 +fi + +# First get headers from the first file +awk '{if ($0 ~ /trkpt/) {exit} else {print}}' "${USABLE_FILES[0]}" + +# Now get the trackpoints from all the usable files +for FILE in "${USABLE_FILES[@]}" +do + awk '/trkpt/,/\/trkpt/' "$FILE" +done + +# Finally, get footers from the final file +# (These should be identical to those of the first file) +tac "${USABLE_FILES[${#USABLE_FILES[@]}-1]}" \ + | awk '{if ($0 ~ /trkpt/) {exit} else {print}}' \ + | tac + -- cgit v1.2.3-89-gcfd4