Date Conversion

Hi

I want to convert date from one format to the other i.e.

From

Thu Mar 6 15:57:39 2014

To

2014-03-06 15:57:39 

Is there any direct command to implement this ?

If you want to print the date in this format, use below

date "+%Y-%m-%d %H:%M:%S"

If you have these details in a file and you want to convert it

awk 'BEGIN{M["Jan"]=1; M["Feb"]=2; M["Mar"]=3; M["Apr"]=4; M["May"]=5
  M["Jun"]=6; M["Jul"]=7; M["Aug"]=8; M["Sep"]=9; M["Oct"]=10;
  M["Nov"]=11; M["Dec"]=12}
  {printf "%04d-%02d-%02d %s\n", $5, M[$2], $3, $4}' file
1 Like