Você pode fazer isso usando o comando GNU date
. Pode usar strings e imprimir a data correspondente:
$ date -d "11/11/2014 04:12:03PM"
Tue Nov 11 16:12:03 CET 2014
Observe, no entanto, que ele não gosta de DD-MM-YYY
:
$ date -d "11-11-2014"
date: invalid date ‘11-11-2014’
Portanto, primeiro execute um sed
em seu arquivo para substituir todo -
por /
. Em seguida, passe isso por read
para obter cada campo em uma variável separada, converter e classificar:
$ sed 's#-#/#g' file | while read date _ hour rest; do
echo "$(date -d "$date $hour" +"%F - %R:%S") $rest"
done | sort -h
2014-11-12 - 00:08:03 lat = 41.937911; lon = /93.369249<br>
2014-11-12 - 00:11:29 lat = 41.949656; lon = /93.329133<br>
2014-11-12 - 00:23:02 lat = 42.025385; lon = /93.347026<br>
2014-11-12 - 00:29:10 lat = 41.033341; lon = /93.380586<br>
2014-11-12 - 00:38:08 lat = 41.036720; lon = /93.436851<br>
2014-11-12 - 00:45:20 lat = 41.998129; lon = /93.400943<br>
2014-11-12 - 00:53:36 lat = 41.961489; lon = /93.414624<br>
2014-11-12 - 03:03:59 lat = 41.990516; lon = /93.430704<br>
2014-11-12 - 03:05:15 lat = 41.001546; lon = /93.443352<br>
Isso funcionará no seu exemplo, mas falhará se você também precisar classificar fevereiro ( 02
) antes de novembro ( 11
). Então, um truque seria imprimir as datas como segundos desde a época , classificar isso e depois removê-las:
$ sed 's#-#/#g' file | while read date _ hour rest; do
printf "%s\t%s %s\n" "$(date -d "$date $hour" +"%s")" "$date - $hour" "$rest"
done | sort | cut -f 2-
11/12/2014 - 12:08:03AM lat = 41.937911; lon = /93.369249<br>
11/12/2014 - 12:11:29AM lat = 41.949656; lon = /93.329133<br>
11/12/2014 - 12:23:02AM lat = 42.025385; lon = /93.347026<br>
11/12/2014 - 12:29:10AM lat = 41.033341; lon = /93.380586<br>
11/12/2014 - 12:38:08AM lat = 41.036720; lon = /93.436851<br>
11/12/2014 - 12:45:20AM lat = 41.998129; lon = /93.400943<br>
11/12/2014 - 12:53:36AM lat = 41.961489; lon = /93.414624<br>
11/12/2014 - 03:03:59AM lat = 41.990516; lon = /93.430704<br>
11/12/2014 - 03:05:15AM lat = 41.001546; lon = /93.443352<br>
11/12/2014 - 03:11:50AM lat = 42.039054; lon = /93.442001<br>
Ou para imprimir as datas no formato 24H:
$ sed 's#-#/#g' file | while read date _ hour rest; do
printf "%s\t%s %s\n" "$(date -d "$date $hour" +"%s")" \
"$(date -d "$date $hour" +"%F - %R:%S")" "$rest"
done | sort | cut -f 2-
2014-11-12 - 00:08:03 lat = 41.937911; lon = /93.369249<br>
2014-11-12 - 00:11:29 lat = 41.949656; lon = /93.329133<br>
2014-11-12 - 00:23:02 lat = 42.025385; lon = /93.347026<br>
2014-11-12 - 00:29:10 lat = 41.033341; lon = /93.380586<br>
2014-11-12 - 00:38:08 lat = 41.036720; lon = /93.436851<br>
2014-11-12 - 00:45:20 lat = 41.998129; lon = /93.400943<br>
2014-11-12 - 00:53:36 lat = 41.961489; lon = /93.414624<br>
2014-11-12 - 03:03:59 lat = 41.990516; lon = /93.430704<br>
2014-11-12 - 03:05:15 lat = 41.001546; lon = /93.443352<br>
2014-11-12 - 03:11:50 lat = 42.039054; lon = /93.442001<br>