summaryrefslogtreecommitdiffstats
path: root/tracks/rename.sh
blob: e1504a9fa166f79f966502db1b77e59f46ad1bc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#! /bin/bash

mkdir -p GPX/Archive

for name in $(ls Route*.gpx Track*.gpx 2>/dev/null); do
    new_name=$(cat "$name" | grep -oP "(?<=<name>).*?(?=</name>)" | head -n 1 | sed -e 's/[^0-9a-zA-Z]\+/_/g').gpx
    if [[ "$name" =~ ^Route ]]; then
	new_name="GPX/$new_name"
    else
	new_name="GPX/Archive/$new_name"
    fi
    echo "Renaming: $name to $new_name"
    mv "$name" "$new_name"
done
[ -f Waypoints.gpx ] && mv Waypoints.gpx GPX/