I need a unix command that would convert the following .csv table using("," rather than ,) from:
.. to
I think an awk or sed command will be able to do it but I can't figure it out.
For those who want to see the raw csv:
"Area","Locale","Date","Prefix","INT","Cap","CF","loss","Fall","WR"
"base","NewYork","20150331","100","0","3.225","3.225","0","0","0"
"base","NewYork","20150930","100","0","3.225","3.225","0","0","0"
"base","NewYork","20160331","100","0","3.225","3.225","0","0","0"
"base","NewYork","20160930","100","0","3.225","3.225","0","0","0"
"base","NewYork","20170331","100","0","3.475","3.475","0","0","0"
"base","NewYork","20170929","100","0","3.475","3.475","0","0","0"
"base","NewYork","20180329","100","0","3.475","3.475","0","0","0"
"base","NewYork","20180928","100","0","3.475","3.475","0","0","0"
"base","NewYork","20190329","100","0","3.475","3.475","0","0","0"
to
"Area","Locale","Date","Prefix","INT","Cap","CF","loss","Fall","WR"
"base","NewYork","3/31/2015","100","0","3.225","3.225","0","0","0"
"base","NewYork","9/30/2015","100","0","3.225","3.225","0","0","0"
"base","NewYork","3/31/2016","100","0","3.225","3.225","0","0","0"
"base","NewYork","9/30/2016","100","0","3.225","3.225","0","0","0"
"base","NewYork","3/31/2017","100","0","3.475","3.475","0","0","0"
"base","NewYork","9/29/2017","100","0","3.475","3.475","0","0","0"
"base","NewYork","3/29/2018","100","0","3.475","3.475","0","0","0"
"base","NewYork","9/28/2018","100","0","3.475","3.475","0","0","0"
"base","NewYork","3/29/2019","100","0","3.475","3.475","0","0","0"
Through Perl.
$ perl -pe 's~^([^,]*,[^,]*,")(\d{4})(0([1-9])|(1[012]))(\d{2})"~\1\4\5/\6/\2"~' file
"Area","Locale","Date","Prefix","INT","Cap","CF","loss","Fall","WR"
"base","NewYork","3/31/2015","100","0","3.225","3.225","0","0","0"
"base","NewYork","9/30/2015","100","0","3.225","3.225","0","0","0"
"base","NewYork","3/31/2016","100","0","3.225","3.225","0","0","0"
"base","NewYork","9/30/2016","100","0","3.225","3.225","0","0","0"
"base","NewYork","3/31/2017","100","0","3.475","3.475","0","0","0"
"base","NewYork","9/29/2017","100","0","3.475","3.475","0","0","0"
"base","NewYork","3/29/2018","100","0","3.475","3.475","0","0","0"
"base","NewYork","9/28/2018","100","0","3.475","3.475","0","0","0"
"base","NewYork","3/29/2019","100","0","3.475","3.475","0","0","0"
"base","NewYork","12/29/2019","100","0","3.475","3.475","0","0","0"
Through sed,
I just replaced \d
in the above Perl regex to [0-9]
because sed won't support \d
notation.
$ sed -r 's~^([^,]*,[^,]*,")([0-9]{4})(0([1-9])|(1[012]))([0-9]{2})"~\1\4\5/\6/\2"~' file
"Area","Locale","Date","Prefix","INT","Cap","CF","loss","Fall","WR"
"base","NewYork","3/31/2015","100","0","3.225","3.225","0","0","0"
"base","NewYork","9/30/2015","100","0","3.225","3.225","0","0","0"
"base","NewYork","3/31/2016","100","0","3.225","3.225","0","0","0"
"base","NewYork","9/30/2016","100","0","3.225","3.225","0","0","0"
"base","NewYork","3/31/2017","100","0","3.475","3.475","0","0","0"
"base","NewYork","9/29/2017","100","0","3.475","3.475","0","0","0"
"base","NewYork","3/29/2018","100","0","3.475","3.475","0","0","0"
"base","NewYork","9/28/2018","100","0","3.475","3.475","0","0","0"
"base","NewYork","3/29/2019","100","0","3.475","3.475","0","0","0"
"base","NewYork","12/29/2019","100","0","3.475","3.475","0","0","0"
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments