3 ms·
You forgot the select(.creditcard) - see my comment on the gist - as this one does not filter out null'ed creditcards: name=`date +'%Y%m%d'`; echo "name,c
by th0br0 11y ago
You forgot the select(.creditcard) - see my comment on the gist - as this one does not filter out null'ed creditcards:
name=`date +'%Y%m%d'`;
echo "name,creditcard" > $name;
jq -r '.[] | select(.creditcard) | [.name, .creditcard] | @csv' data.json >> $name
- vitorbaptistaa 11y agoYou're right! I missed that requirement.
- nburger 11y agoIf we're going for succinctness, you could combine these all together: (echo '"Name","Credit Card"'; jq -r '.[] | select(.creditcard) | [.name, .creditcard] | @csv' data.json) >> `date +%Y%m%d`.csv
- vitorbaptistaa 11y agoNice trick to write the headers, thanks!
- ekimekim 11y agoI used jq as well, though instead of doing a seperate echo I did this: ([{name: "name", creditcard: "creditcard"}] + .)[] instead of .[] Another less hacky way would be: [["name", "creditcard"]] + map(select(.creditcard) | [.name, .creditcard]) | .[] | @csv