Article 5JWD5 Using sed to modify the date/time in a gpx file

Using sed to modify the date/time in a gpx file

by
Johng
from LinuxQuestions.org on (#5JWD5)
I have some gpx files that I want to modify the date/time. Typically the lines look like:
Code: <time>2001-10-23T21:02:56.000Z</time>
<time>2001-10-23T21:26:27.000Z</time>
<time>2001-10-23T22:57:21.000Z</time>
<time>2001-10-23T23:00:10.000Z</time>
<time>2001-10-24T00:49:47.000Z</time>
<time>2001-10-24T01:56:57.000Z</time>
<time>2001-10-24T02:39:59.000Z</time>I have created a script to modify the dates in the file, by adding 7168 days to the date:
Code:#!/bin/bash
echo GPX files: `ls -1 *.gpx`
echo
echo -n "Enter filename: "
read -e FILENAMEX

FILENAME=$FILENAMEX
echo

Day1=$(grep -m1 'time' $FILENAME)
Day2=$(grep time $FILENAME | tail -1)

echo "Day1: " "$Day1"
echo "Day2: " "$Day2"
echo

MYVAR="$Day1"
Date1=${MYVAR%T*}
echo "Date1: ""$Date1"

MYVAR="$Date1"
Date1x=${MYVAR##*>}

MYVAR="$Day2"
Date2=${MYVAR%T*}
echo "Date2: ""$Date2"

MYVAR="$Date2"
Date2x=${MYVAR##*>}

echo "$Date1x $Date2x"

TrueDate1=$(date -d "$Date1x 7168 days" +%F)

TrueDate2=$(date -d "$Date2x 7168 days" +%F)

echo "$TrueDate1 $TrueDate2"

sed "s/$Date1x/$TrueDate1/g; s/$Date2x/$TrueDate2/g" "$FILENAME" > "$TrueDate2".gpx

FILENAMEz="$TrueDate2".gpx

Day1t=$(grep -m1 'time' $FILENAMEz)
Day2t=$(grep time $FILENAMEz | tail -1)

echo "Day1t: " "$Day1t"
echo "Day2t: " "$Day2t"Now I need help to change the two digit value after the "T" in each line by adding 12 if the hour is less than 12, or minus 12 if the hour is greater than 12latest?d=yIl2AUoC8zA latest?i=FUF6epU4XgM:VmHWZeRRlIE:F7zBnMy latest?i=FUF6epU4XgM:VmHWZeRRlIE:V_sGLiP latest?d=qj6IDK7rITs latest?i=FUF6epU4XgM:VmHWZeRRlIE:gIN9vFwFUF6epU4XgM
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments