Created
September 20, 2019 15:33
-
-
Save timwis/1ba8e424e27c6c9dfcd97c59426bc913 to your computer and use it in GitHub Desktop.
Import and export CSV files with orc
This file contains hidden or 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
#!/usr/bin/env bash | |
import () { | |
csvjson "${3:-/dev/stdin}" \ | |
| jq --raw-output '.[] | @sh "echo orc add-entry '"$1"' user \(.'"$2"') \(tostring)"' \ | |
| xargs -0 bash -c | |
} | |
export_ () { | |
orc ls "$1" user | cut -f 4 | in2csv -f ndjson | |
} | |
usage () { | |
cat <<EOF | |
usage: | |
orcsv import <REGISTER> <KEYFIELD> <FILENAME> | |
cat <FILENAME> | orcsv import <REGISTER> <KEYFIELD> | |
orcsv export <REGISTER> | |
dependencies: | |
orc: https://github.com/register-dynamics/orc | |
csvkit: https://csvkit.rtfd.org | |
jq: https://stedolan.github.io/jq/ | |
EOF | |
} | |
case $1 in | |
import) shift; import "$@";; | |
export) shift; export_ "$@";; | |
*) usage; exit 1;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment