Skip to content

Instantly share code, notes, and snippets.

@jakekara
Last active October 3, 2018 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakekara/38b3b514856c2062b07353a72d59973c to your computer and use it in GitHub Desktop.
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...
#!/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