-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output to multiple files #2438
Comments
You can bind shell variables by evaluating jq output. eval "$(jq -nr '{x:1,y:{y:2},z:{"some":"large json"}} | @sh"x=\(.x|tojson); y=\(.y|tojson); z=\(.z|tojson)"')"
echo "$x"
echo "$y"
echo "$z" |
Someone asked time ago on the I proposed this solution: #!/bin/sh --
jq -r '
try ( [ .index, .isActive ] | @tsv "1\(.)"),
try (.friends[] | [ .name, .age ] | @tsv "2\(.)"),
try (.companies[] | [ .name, .address ] | @tsv "3\(.)")
' file.jsonl \
| sed -n -e 's/^1//w file1.tsv' -e t \
-e 's/^2//w file2.tsv' -e t \
-e 's/^3//w file3.tsv' N.B. if your output is not |
Thanx, I've tried both. |
I need to move the values of some keys of a large JSONs input into separate files. Currently, this requires writing several
jq
commands for the same JSON, which is very slow with large inputs.It would be great if
jq
could read and parse JSON once and then output to different files.Alternatively, it could set ENV variables so I can write files outside of
jq
.The text was updated successfully, but these errors were encountered: