Skip to content

Instantly share code, notes, and snippets.

@framundo
Created December 1, 2017 17:48
Show Gist options
  • Save framundo/99ebb2a7caa38f6612c78b8aaf24d81b to your computer and use it in GitHub Desktop.
Save framundo/99ebb2a7caa38f6612c78b8aaf24d81b to your computer and use it in GitHub Desktop.
CSV Sanitizer
#!/bin/bash
iconv -f ISO-8859-1 -t utf-8 $1 > utf8.csv
perl -pi -e 's/\r\n|\n|\r/\n/g' utf8.csv # Convert to UNIX
sed -e 's/,/\./g' -e 's/"/\\"/g' -e 's/;/","/g' -e 's/$/"/' -e 's/^/"/' utf8.csv > out.csv
gawk -F',' -v OFS=',' '{NF=6}1' out.csv > padded.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment