Skip to content
Advertisement

Convert CSV to TSV

How do you convert this csv file into a tab delimited file?

JavaScript

Notice both the Surverys and Response columns are empty strings.

I use this code to convert it to a tab file –

JavaScript

It doesn’t convert the last column though. This is the output I get (Notice the last column is omitted) –

JavaScript

There are 8 columns in the header and only 7 columns in the tab delimited data, so the last column is missed.

UPDATE

My column names have commas in them.

Advertisement

Answer

With GNU awk.

JavaScript

Output:

"Country"      "Percent"       "Percent of patients"   "home health"   "home health agency"    "friends and family"       "Surveys"       "Response"
"Nation"        "88"    "85"    "83"    "84"    "78"    ""      ""
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement