Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jq combine output on a single line separated by space

Tags:

jq

I am trying to run a jq query on a windows machine and it extracts values from output on a separate line

jq -r .Accounts[].Id

Output

204359864429
224271824096
282276286062
210394168456
090161402717

How do I run the jq query so that it combines the output on a single line separated by space

This is what I need-

204359864429 224271824096 282276286062 210394168456 090161402717

Any help would be appreciated.

like image 372
starchaser Avatar asked Jul 05 '19 06:07

starchaser


1 Answers

The usual way would be to use the @csv or @tsv operators to convert the result in the CSV or tab-delimited format. These operators need the result to be contained in an array. For your case also to have a single space delimit, we can do a simple join(" ") operation

jq -r '[.Accounts[].Id]|join(" ")'
like image 63
Inian Avatar answered Sep 21 '22 09:09

Inian