Last active
July 10, 2020 01:23
-
-
Save therealmitchconnors/e8e1a44c7e87387845a8d83f699d7dd6 to your computer and use it in GitHub Desktop.
Reads STDIN json, writes STDOUT 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
# 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