Skip to content

Instantly share code, notes, and snippets.

@schutt
Created August 25, 2023 20:32
Show Gist options
  • Save schutt/9f2ba145c85878e76588af0f4d013b80 to your computer and use it in GitHub Desktop.
Save schutt/9f2ba145c85878e76588af0f4d013b80 to your computer and use it in GitHub Desktop.
Cassandra cqlsh query output to CSV
#!/bin/zsh
# Cassandra cqlsh output is pipe delimited, it is useful to directly pipe query results to CSV instead.
if [ -p /dev/stdin ]; then
sed 's/\ //g; /^----.*/d; /^(/d; /^\s*$/d; s/|/,/g;'
else
echo "No input on stdin."
fi
@schutt
Copy link
Author

schutt commented Aug 25, 2023

I've been using sed script in this zsh script for quick test queries for years. It has been so long that I don't remember if I wrote the regular expressions or borrowed them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment