awk command to manipulate csv file in UNIX

Hi,

I am new to awk/unix and am trying to put together a script to manipulate the date column in a csv file.

I have file1.csv with the following contents:

Date,ID,Number,Amount,Volume,Size
01-Apr-2014,WERFG,998,105873.96,10873.96,1342.11
01-Apr-2014,POYFR,267,5681.44,5681.44,462.96

I want to format the date column as follows -> yyyy-mm-dd and want the output saved in a tempfile:

Date,ID,Number,Amount,Volume,Size
2014-04-01,WERFG,998,105873.96,10873.96,1342.11
2014-04-01,POYFR,267,5681.44,5681.44,462.96

Is there a simple awk script to achieve this?

Appreciate the help!!

Thanks,

awk 'BEGIN { months["Jan"] = "01"
             months["Feb"] = "02"
             months["Mar"] = "03"
             months["Apr"] = "04"
             months["May"] = "05"
             months["Jun"] = "06"
             months["Jul"] = "07"
             months["Aug"] = "08"
             months["Sep"] = "09"
             months["Oct"] = "10"
             months["Nov"] = "11"
             months["Dec"] = "12"
             sep="-"
             }
    NR>1   { split($1,a,sep) 
             $1=a[3] sep months[a[2]] sep a[1]
           }1' OFS=\, FS=\, file1.csv > tempfile
1 Like

That worked perfectly!! Thank you so much!! :slight_smile: