Skip to content

Instantly share code, notes, and snippets.

@sephraim
Created March 2, 2015 16:29
Show Gist options
  • Save sephraim/252c0b06c9e424ab82ab to your computer and use it in GitHub Desktop.
Save sephraim/252c0b06c9e424ab82ab to your computer and use it in GitHub Desktop.
Convert a TSV (tab-separated values) file to a CSV (comma-separated values) file
#!/bin/sh
# Convert a TSV (tab) file to a CSV (comma) file
#
# Please note that this will surround all values with
# double-quotes. All other double-quotes will be escaped.
#
# Example usage:
# ./tab2csv.sh myfile.tsv > myfile.csv
sed 's/"/\\"/g' $1 \
| sed $'s/\t/","/g' \
| sed 's/^/"/g' \
| sed 's/$/"/g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment