replace tab with space

2018-06-24 18:29:21

input json:

[

{

"name": "cust1",

"grp": [

{

"id": "46",

"name": "BA2"

},

{

"id": "36",

"name": "GA1"

},

{

"id": "47",

"name": "NA1"

},

{

"id": "37",

"name": "TR3"

},

{

"id": "38",

"name": "TS1"

}

]

}

]

how to get .grp[] names separated with space on @tsv output?

$ jq -r '.[]|[.name, (.grp//[{"name":"-"}]|.[]|" ",.name)]|@tsv' test_inp

cust1 BA2 GA1 NA1 TR3 TS1

expected output for above sample:

cust[TAB]BA2[SPACE]GA1[SPACE]NA1[SPACE]TR3[SPACE]TS1

jq approach:

jq -r '.[] | [.name, (.grp | map(.name) | join(" "))] | @tsv' input.json

The output:

cust1 BA2 GA1 NA1 TR3 TS1

  • jq approach:

    jq -r '.[] | [.name, (.grp | map(.name) | join(" "))] | @tsv' input.json

    The output:

    cust1 BA2 GA1 NA1 TR3 TS1

    2018-06-24 18:43:03