Here is the short version of my question: how do you convert comma-separated lists of dates from one format to another? More specifically, I'd like a single one-line command which converts strings of this form:
YYYY/MM/DD,YYYY/MM/DD
to strings of the following form:
DD/MM/YYYY,DD/MM/YYYY
Now I'll describe the context for my question.
I have a CSV file whose rows contain pairs of adjacent dates in the following format:
YYYY/MM/DD
I run the following grep
command to extract the pair of dates:
grep -Po '[1-2][0-1][0-9][0-9]/[0-1][0-9]/[0-1][0-9]','[1-2][0-1][0-9][0-9]/[0-1][0-9]/[0-1][0-9]' file.csv`
This results, for example, in strings such as the following:
2016/05/16,2017/06/15
I am able to convert a single date-string using the date
command as follows:
date -d '2016/05/16' '+%d/%m/%Y'
This produces the desired result:
16/05/2016
I tried applying this command to multiple input strings, e.g.:
date -d"2016/05/16","2017/06/15" "+%d-%m-%Y"
But that didn't work. I received the following error message:
Error :- Invalid date - 2016/05/16,2017/06/15'
What I want is a single command which will convert 2016/05/16,2017/06/15
to 16/05/2016,15/06/2017
.
file.csv
grep
actually have anything to do with this question? Please do not respond in comments; edit your question to make it clearer and more complete.