diff options
| author | rrueger <rrueger.github@velleto.com> | 2021-07-18 23:21:03 +0200 |
|---|---|---|
| committer | rrueger <rrueger.github@velleto.com> | 2021-07-18 23:21:03 +0200 |
| commit | 5b693c5af93a6ad9893d7ad52f4204b7b6b7c4db (patch) | |
| tree | 0f16fab35f977dc5e0dd947cfb397f92ad79c054 /combine-gpx | |
| parent | fed42bf0396e805bf31cd48589a590f33733558c (diff) | |
| download | gpxtools-5b693c5af93a6ad9893d7ad52f4204b7b6b7c4db.tar.gz gpxtools-5b693c5af93a6ad9893d7ad52f4204b7b6b7c4db.tar.bz2 gpxtools-5b693c5af93a6ad9893d7ad52f4204b7b6b7c4db.zip | |
Add combine-gpx
Diffstat (limited to 'combine-gpx')
| -rwxr-xr-x | combine-gpx | 46 |
1 files changed, 46 insertions, 0 deletions
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 1> <FILE 2> [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 + |