summary refs log tree commit diff
path: root/bin/jq-table
blob: 55d16fb61ce49640c0a969a6c019ce843e4be9d2 (plain) (blame)
1
2
3
4
5
6
7
8
#!/bin/bash
tsv=$(jq 'def hdr:to_entries|map(.key); def vals:to_entries|map(.value|tostring); (arrays|[(first|hdr)]+[.[]|vals]) // (objects|[hdr]+[vals])|.[]|@tsv' -r)
col=$(head -n1 <<<"$tsv" | tr '\t' ',' | tr '[:lower:]' '[:upper:]')
if [ "$1" = "--headers" ]; then
	echo "$col"
	exit 1
fi
exec column -s $'\t' --table --table-columns "$col" "$@" <(tail -n+2 <<<"$tsv")