Skip to content

Instantly share code, notes, and snippets.

@andrewharvey
Created October 29, 2011 09:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewharvey/1324287 to your computer and use it in GitHub Desktop.
Save andrewharvey/1324287 to your computer and use it in GitHub Desktop.
Converts a multi-line formatted SQL query into an escaped single line string for inclusion in a JSON based MML file.
#!/bin/sh
# Converts a multi-line formatted SQL query into an escaped single line string
# for inclusion in a JSON based MML file.
# Reads from stdin and writes to stdout.
sed '{:q;N;s/\n/\\n/g;t q}'
#!/bin/sh
# Converts a multi-line formatted SQL query into an escaped single line string
# for inclusion in a JSON based MML file.
# It also encases the query in "( [query] ) AS [table]" as required for your
# MML's table field.
# Reads from stdin and writes to stdout.
sed '{:q;N;s/\n/\\n /g;t q}' | sed 's/^/(\\n /g' | sed 's/$/\\n) AS /g'
#!/bin/sh
# Converts a single-line SQL statement from a JSON based MML file into a
# multi-line formatted SQL query.
# Reads from stdin and writes to stdout.
sed 's/\\n/\n/g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment