I have json log file like

{"type":"1","fname":"AAA","lname":"bbb" }
{"type":"2","state":"gujarat" }
{"type":"3","city":"ahmedabad" }
{"type":"3","city":"rajkot" }
{"type":"1","fname":"ccc","lname":"ddd" }

I run following command

jq -c "select(.type==\"1\")|{fname:.fname}" > type_1.txt
jq -c "select(.type==\"2\")|{city:.city}" > type_3.txt

Is anyway to run jq command only one time and generate 2 output files?


It's not possible to avoid second invocation of jq, sorry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.