Reputation: 35
I have downloaded this CSV file: https://www.nhsbsa.nhs.uk/sites/default/files/2020-05/Dispensing%20Data%20Jan%2020%20-%20CSV.csv
and am trying to add a column on to the end with a value of "null" for every row.
I have tried using this awk
command:
awk 'BEGIN{FS=OFS=","}{print $0 OFS "null"}' ogfile.csv > newfile.csv
but it appears to be adding a new row after every row, with the second column having a field of "null"
new rows instead of new column
can anyone help me understand why this is happening?
Upvotes: 1
Views: 380
Reputation: 113834
Your source file has DOS/Windows line endings. When one sees anomalous output, this is a good first item to check. Two solutions:
dos2unix
to remove the unwanted \r
character from your input file. dos2unix
is available on most distributions.or,
Modify your awk command to recognize and remove the offending characters:
awk 'BEGIN{RS="\r\n"; FS=OFS=","}{print $0 OFS "null"}' ogfile.csv
Upvotes: 1