Last active
October 3, 2018 12:49
-
-
Save jakekara/38b3b514856c2062b07353a72d59973c to your computer and use it in GitHub Desktop.
Convert a SQL text output to CSV, for when someone sends you SQL text output of a table instead of a CSV...
This file contains 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
#!/usr/bin/env sh | |
# | |
# clean-mess.sh - Convert a SQL text output to CSV, for when | |
# someone sends you SQL text output of a table instead of a CSV... | |
# | |
# Beware, this will not properly handle double spaces in a column | |
# because that wasn't an issue for the data I received. | |
# | |
# In this case, it just does every .mess file in a folder called data | |
# but this could easily be made into a reusable function | |
# | |
for INFILE in $(ls data/*.mess); do | |
OUTFILE="$INFILE.csv" | |
echo "Processing $INFILE to $OUTFILE" | |
# Sed string for the sed that comes with MacOS. I think you can use | |
# \+ with other other versions | |
cat $INFILE | sed 's/ */,/g' > $OUTFILE | |
done; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment