Skip to content

Instantly share code, notes, and snippets.

@geoffgarside
Created September 17, 2013 08:47
Show Gist options
  • Save geoffgarside/6591770 to your computer and use it in GitHub Desktop.
Save geoffgarside/6591770 to your computer and use it in GitHub Desktop.
Convert a semicolon separated values file into CSV with proper escaping of commas. Assumes theres are no double quotes in the file already.
awk '{ end=split($0,a,";"); result = a[1]; for(i = 2; i <= end; i++) { if (index(a[i], ",")) { a[i] = "\"" a[i] "\""; } result = result "," a[i]; } print result }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment