Skip to content

Instantly share code, notes, and snippets.

@aduzsardi
Last active March 4, 2019 07:13
Show Gist options
  • Save aduzsardi/3604ecb11bff9b2adb1c58450364ae5c to your computer and use it in GitHub Desktop.
Save aduzsardi/3604ecb11bff9b2adb1c58450364ae5c to your computer and use it in GitHub Desktop.
tsv2csv_v2
function tsv2csv() {
if [[ $# -ne 1 ]]; then
echo "Usage: ./$0 tab-delimited-file.txt"
else
tr -d '\r' < "$1" | sed -r -e 's/\t/","/g' -e 's/^/"/g' -e 's/\s+(")/\1/g' -e 's/(\s+)?$/"/g' > "$1".csv
fi
}
function tsv2csvall() {
OIFS="$IFS"
IFS=$'\n'
for f in $(ls /cygdrive/c/Users/win10/Desktop/Events/*.txt); do
if [[ ! -f "${f}.csv" ]]; then
echo "Converting to CSV file: ${f}"
tr -d '\r' < "${f}" | sed -r -e 's/\t/","/g' -e 's/^/"/g' -e 's/\s+(")/\1/g' -e 's/(\s+)?$/"/g' > "${f}".csv
fi
done
IFS="$OIFS"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment