I am manipulating data from a text file with the following data structure:
"1111","2222","3333","4444","5555","6666","7777","2017/12/15 16:26:00"
I am trying to change the '/' in the date to '-'. Here is my awk command:
awk -F "," '{gsub("/", "-", $8); print}' my-input.txt
It successfully changes the /, but has the unintended consequence of replacing the ',' commas with a ' ' space character:
"1111" "2222" "3333" "4444" "5555" "6666" "7777" "2017-12-15 16:26:00"
Does anyone know why this is happening?
awk -F "," 'BEGIN {OFS = ",";} {gsub("/", "-", $8); print}' my-input.txt
orawk -F "," -v OFS="," '{gsub("/", "-", $8); print}' my-input.txt
– taliezin Mar 1 '18 at 9:13,
, and you want to keep it, then you have to define your output file separator as well. – pfnuesel Mar 1 '18 at 9:16