#!/bin/bash PROGNAME=${0##*/} DSTGPX=$(mktemp /tmp/$PROGNAME.XXXXXXXX.gpx) SRCGPXS=( ~/doc/def/travel/holidays/*/tracks/alexis/*simpl*.gpx ) # Combine all tracks into one file. gpsbabel -i gpx $(for SRCGPX in "${SRCGPXS[@]}"; do echo -n "-f $SRCGPX "; done) -x simplify,count=800 -o gpx -F $DSTGPX # Strip out an GPX extensions (which, in my experience, only define # track colours). perl -0777 -pi -e 's/.*?<\/extensions>\n//sg' $DSTGPX # Insert new colours. I've spread the RHS of the s/.../.../ over # several lines and added '/x' modified but this doesn't entirely # behave as I wanted (extra newlines are in the output). But # it still is valid GPX and it is more readable. perl -0777 -pi -e ' BEGIN { # Colours list taken from GORP. @colours=qw/DarkRed DarkGreen DarkBlue DarkMagenta DarkCyan Red Green Yellow Blue Magenta Cyan/; # We will start with colour #0. $i=0; } # Insert colour-defining GPX extension block immediately after # track name. s/ (.*?.*?<\/name>\n) / $1 $colours[($i++)%($#colours+1)]<\/gpxx:DisplayColor> <\/gpxx:TrackExtension> <\/extensions> /sgx ' $DSTGPX echo $DSTGPX