The input.csv is:
id, name, shortName
1, Example1, Ex1
2, Example2, Ex2
I need to add a column of date. So the output.csv should be:
id, 2021-06-23, name, shortName
1, 2021-06-23, Example1, Ex1
2, 2021-06-23, Example2, Ex2.
For this purpose, i used this comand:
awk -F"," 'BEGIN { FS=OFS = "," } {$2="2021-06-23"; print}' input.csv
But, when i did it the column "name" was deleted. The output was like this:
id, 2021-06-23, shortName
1, 2021-06-23, Ex1
2, 2021-06-23, Ex2.
Then, i also tried put the colum at the end with the comand:
awk -F"," 'BEGIN { FS=OFS = "," } {$4="2021-06-23"; print}' input.csv
But the exit was even stranger:
, 2021-06-23
, 2021-06-23
, 2021-06-23
So, I would like to know what I'm doing wrong both in the case of adding a column to the middle of the csv file and adding it to the end.
Obs.: I am now learning how to use it and therefore I believe that my mistakes must be a beginner's mistakes.
\r\n) and therefore the latter output is a mess.RS="\r\n"probably fixes that. To get the expected output,$2="2021-06-23" OFS $2should work.