I am trying to change the date format in a text file so that it can be comma-delimited by Year, Month, and Day. Currently, it is in YYYY-MM-DD format and I am trying to replace the hyphens with commas without affecting the other hyphenated text in the file:
2011-1-1,59,44,29,55,42,26,93,80,66,30.15,30.05,29.96,10,8,4,14,3,22,T,7,Rain,201,39.2,76.7,KBWI
2011-1-26,35,34,32,34,31,25,100,82,64,30.04,29.79,29.54,9,2,0,22,11,29,1.82,8,Fog-Rain-Snow-Thunderstorm,23,39.2,76.7,KBWI #I dont want to remove the hyphens for the weather events
A friend told me to use regex with this expression:
re.findall('[\d]{4}-[\d]{1,2}-[\d]{1,2}')
It does find the patterns for all the dates formatted with hyphens, but I have no clue as to how to replace the hyphens with commas for all the lines in the textfile with this match. I'm thinking about creating a new text file with the edited data so that I can use it in another application. Any help would be appreciated.