This is not too rare of a problem… actually with quite a simple solution: you have a collection of GPS tracks – e.g. recorded via an app on your mobile phone – which you want to organize in such a way, that you end up with one file per day. For whatever reason no complete track was generated in the first place, but instead of keeping all the little bit around, you’d rather end up with one data set containing the individual segments; that this indeed can be accomodated becomes evident from keeping in mind that basically a GPX file internally uses XML in order to represent the track information.

    <trkpt lat="50.709352059179835" lon="7.046773483076821">
      <ele>170.5547262157751</ele>
      <time>2014-01-12T13:21:00Z</time>
      <extensions>
        <gpx10:speed>1.0826374292373657</gpx10:speed>
        <ogt10:accuracy>8.0</ogt10:accuracy>
        <gpx10:course>321.3857421875</gpx10:course>
      </extensions>
    </trkpt>

If you look at the file as a whole, you willl notice that following the file-header there is a block enclosing the information of the track

    <?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
    <gpx version="1.1" creator="OsmAnd" ...>
      <trk>

        ...

      </trk>
    </gpx>

As a result of the above it becomes rather straight forward how to combine individual tracks into a single data set. While of course a number of tools exist which will help you to do the job, all it actually needs is a text editor

1. Concatenate the individual files – this e.g. can be done via a simple set of Bash instructions, such as

    FILES=`ls 2013-12-16_*`
    for FILE in $FILES ; { cat $FILE >> 2013-12-16.gpx ; rm $FILE ; } ;

The resulting data set will look something along the following lines:

          <trkpt lat="50.779999" lon="7.1845283">
            <ele>105.79742782151801</ele>
            <hdop>8.0</hdop>
            <time>2013-12-16T07:55:11Z</time>
          </trkpt>
        </trkseg>
      </trk>
    </gpx>
    <?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
    <gpx version="1.1" creator="OsmAnd" ...>
      <trk>
        <trkseg>
          <trkpt lat="50.7784425" lon="7.077948">
            <ele>88.98101672681007</ele>
            <hdop>8.0</hdop>
            <time>2013-12-16T11:09:34Z</time>
          </trkpt>

2. Remove end-of-file marker and the file-header in between tracks:

          <trkpt lat="50.779999" lon="7.1845283">
            <ele>105.79742782151801</ele>
            <hdop>8.0</hdop>
            <time>2013-12-16T07:55:11Z</time>
          </trkpt>
        </trkseg>
      </trk>
      <!-- Begin of next track -->
      <trk>
        <trkseg>
          <trkpt lat="50.7784425" lon="7.077948">
            <ele>88.98101672681007</ele>
            <hdop>8.0</hdop>
            <time>2013-12-16T11:09:34Z</time>
          </trkpt>

There you go – all of the individual tracks have been merged (or combined) into a single data set, which then in turn will make e.g. matching of pictures to the track information (in ordet to embed the GPS data) considerably more simple than needing to deal with a whole bunch of individual shorter tracks.