I have a csv file (named
a.csv) exported from DB mongo like this:
... ABC,DN,1000,RENEW_DAY,Thu Apr 27 2017 23:19:47 GMT+0700 (ICT),1,1,4,-1 ANSLAS,DN,1000,RENEW_DAY,Thu Apr 27 2017 23:19:52 GMT+0700 (ICT),1,1,4,-1 ...
I want to import this file to MySQL but this date format cannot be inserted. So I have an idea to convert this to be
b.csv before insert to MySQL
... ABC,DN,1000,RENEW_DAY,2017-04-27 23:19:47,1,1,4,-1 ANSLAS,DN,1000,RENEW_DAY,2017-04-27 23:19:52,1,1,4,-1 ...
This is the bash command bash I use to convert date in bash
date -d"Thu Apr 27 2017 23:19:52 GMT+0700 (ICT)" +'%Y-%m-%d %H:%M:%S'
So how can I convert this automatically with the bash shell like this
./process.sh a.csv b.csv?
#!/bin/bash # Environment filename=$1 filelines=`cat $filename` for phone in $filelines ; do <HOW CAN CUT Filed Date and convert this and export to b.csv file> done