pinpe
1
Hi Guys,
Can someone help me on how to change the date format using sed or any unix command to give my desired output as shown below.
INPUT FILE:
69372,200,20100122T17:56:02,2
53329,500,20100121T11:50:07,2
48865,100,20100114T16:08:16,2
11719,200,20100108T13:32:20,2
DESIRED OUTPUT FILE:
69372,200,22-JAN-10 05.56.02 PM,2
53329,500,21-JAN-10 11.50.07 AM,2
48865,100,14-JAN-10 04.08.16 PM,2
11719,200,08-JAN-10 01.32.20 PM,2
Thanks in advance.
Br,
Pinpe
Manually (and noisy) with awk (without GNU extensions):
awk -F, 'BEGIN {
split( "JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC", m )
}
{
am = substr( $3, 10, 2) > 12 ? "PM" : "AM"
$3 = substr($3, 7, 2) "-" m[substr($3, 5, 2) + 0] "-" \
substr( $3, 3, 2) " " ( am == "PM" ? sprintf( "%0.2d", substr( $3, 10, 2) - 12 ) \
: sprintf( "%0.2d", substr( $3, 10, 2) ) ) \
"." substr( $3, 13, 2 ) "." substr( $3, 16, 2 ) " " am
}3' OFS=, infile
1 Like
pinpe
3
Perfect! Thanks so much radoulov!