本文介绍了使用jq从JSON连连看数字而不带双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有每行1个json文档的文件,每个文档中的字段start_idend_id.我想使用jq提取它们并将它们打印在同一行上.

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.

到目前为止,我有:

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

这可行,但是我需要sed删除双引号.

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

为了改进我的jq-foo,有没有办法在不使用sed的情况下完成 ?

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

例如给

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

获取

1 50
50 99
99 12

代替

"1 50"
"50 99"
"99 12"

推荐答案

默认情况下,jq将其输出格式化为有效的JSON值.这意味着字符串用引号引起来.

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

幸运的是,--raw-output-r参数将覆盖该行为,因此您的字符串输出可以摆脱那些讨厌的引号;)

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

来源: https://stedolan.github.io/jq/manual/

这篇关于使用jq从JSON连连看数字而不带双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 00:51