Skip to content

Instantly share code, notes, and snippets.

@therealmitchconnors
Last active July 10, 2020 01:23
Show Gist options
  • Save therealmitchconnors/e8e1a44c7e87387845a8d83f699d7dd6 to your computer and use it in GitHub Desktop.
Save therealmitchconnors/e8e1a44c7e87387845a8d83f699d7dd6 to your computer and use it in GitHub Desktop.
Reads STDIN json, writes STDOUT csv
# converts spanner queries to csv on the command line
# input should be like `gcloud spanner databases execute-sql --format json`
STDIN=$(cat -)
echo $(echo "$STDIN"| jq '.metadata.rowType.fields[].name' | tr '\n' ', ')
rows=$(echo "$STDIN"| jq -r '.rows[] | @csv')
printf '%s\n' "${rows[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment