Hi Raghureds,
I'm not nearly as fluent in perl
as Aia, but the following awk
code seems to do what you want (and it won't report that times between 12:00:00 and 12:59:59, inclusive, are AM instead of PM).
awk '
BEGIN { FS = OFS = ","
}
{ sub(/\r/, "")
split($NF, d, /[ :]/)
ampm = (d[2] > 11) ? "PM" : "AM"
if(d[2] > 12)
d[2] -= 12
if(d[2] == "00")
d[2] = 12
$NF = sprintf("%s %02d:%s:%s %s", d[1], d[2], d[3], d[4], ampm)
}
1' file.csv
If you want to try this on a Solaris/SunOS system, change awk
to /usr/xpg4/bin/awk
or nawk
.
If file.csv
contains:
,750,0000000000000000GCJR, ,06/22/2016 14:48:44
,750,0000000000000000GCJR, ,06/22/2016 12:48:44
,750,0000000000000000GCJR, ,06/22/2016 02:48:44
,750,0000000000000000GCJR, ,06/22/2016 00:48:44
it produces the output:
,750,0000000000000000GCJR, ,06/22/2016 02:48:44 PM
,750,0000000000000000GCJR, ,06/22/2016 12:48:44 PM
,750,0000000000000000GCJR, ,06/22/2016 02:48:44 AM
,750,0000000000000000GCJR, ,06/22/2016 12:48:44 AM
which, I think, is what you wanted.
Hope this helps...