I want to generate some nice graphs by using existing and auto generated data files. Unfortunately I cannot change the format of the files.
The lines contain a time
The following awk
script will format your file:
awk '{time = $5; if(substr(time,6,2) == "PM" \
&& substr(time,1,2) < 12) add = 12; else add = 0; \
$5 = substr(time,1,2)+add "" substr(time,3,3); \
print $0}' data
so that
July 06, 2014 at 10:46AM 83.6
July 06, 2014 at 12:46PM 84.6
July 06, 2014 at 10:46PM 85.6
will look like
July 06, 2014 at 10:46 83.6
July 06, 2014 at 12:46 84.6
July 06, 2014 at 22:46 85.6
within gnuplot you can do this dynamically when plotting your file. You can do (note I need to escape the "
):
set timefmt "%B %d, %Y at %H:%M"
set xdata time
set format x "%H:%M"
plot "< awk '{time = $5; if(substr(time,6,2) == \"PM\" \
&& substr(time,1,2) < 12) add = 12; else add = 0; \
$5 = substr(time,1,2)+add \"\" substr(time,3,3); \
print $0}' data" u 1:6 w l
Note I am assuming that 00:15 is 00:15AM. If your output is 12:15AM then you need to modify the script accordingly. Something along these lines:
if(substr(time,6,2) == "AM" && substr(time,1,2) == 12) add = -12