Last active
March 4, 2019 07:13
-
-
Save aduzsardi/3604ecb11bff9b2adb1c58450364ae5c to your computer and use it in GitHub Desktop.
tsv2csv_v2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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