39

I have files with 1 json document per row and the fields start_id and end_id in each document. I'd like to use jq to extract these and print them on the same row.

So far I have:

cat part* | jq '"\(.start_id) \(.end_id)"' | sed s/\"//g | head

This works, but I need the sed to remove the double quotes.

In order to improve my jq-foo, is there a way to do this without using sed?

e.g. given

{"start_id":1,"end_id":50}
{"start_id":50,"end_id":99}
{"start_id":99,"end_id":12}

get

1 50
50 99
99 12

instead of

"1 50"
"50 99"
"99 12"
Bonifacio2
  • 3,405
  • 6
  • 34
  • 54
Synesso
  • 37,610
  • 35
  • 136
  • 207

1 Answers1

61

By default, jq formats its output to be a valid JSON value. This means that character strings are wrapped in quotes.

Fortunately, the --raw-output or -r parameter overrides that behaviour so your string output can be free of those nasty quotation marks.

2240
  • 1,547
  • 2
  • 12
  • 30
xjedam
  • 1,026
  • 12
  • 15