2 ms·
<input.json jq -S -r '(first | keys) , (.[]| [.[]]) | @tsv' <input.json # redir jq -S # sort -r # raw string out '
by nh23423fefe 7mo ago
<input.json jq -S -r '(first | keys) , (.[]| [.[]]) | @tsv'
<input.json # redir
jq
-S # sort
-r # raw string out
'
(first | keys) # header
, # comma is generator
(.[] | # loop input array and bind to .
[ # construct array
.[] # with items being the array of values of the bound object
])
| @tsv' # generator binds the above array to . and renders to tsv
- randusername 7mo agooh my god how could I have been doing this for so long and not realize that you can redirect before your binary. I knew cat was an anti-pattern, but I always thought it was so unreadable to redirect at the end
- attentive 7mo agoit seems smart until you accidently type >input.json and nuke the file
- figmert 7mo agoYou can use sponge for that.
- HappMacDonald 7mo agoThat sounds like a mistake which would be easily to make at the end of the line, unless you are contrasting input stream redirect against cat regardless where it's written on the line?