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来删除双引号.

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}

到达

1 50
50 99
99 12

而不是

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

推荐答案

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

幸运的是,--raw-output-rparameter overrides有这样的行为,所以您的字符串输出可以没有那些讨厌的引号.

Json相关问答推荐

使用WSO2 JsonTransform Mediator对空值执行JsonExceptionUndeletedOperationException

如何循环访问多个子数组并在单个JSON中检索数据点

报告重复的对象键

Jolt - 如何比较 if else 条件的两个值

在 NX 工作区中跨多个应用共享 ngx-translate 翻译文件

如何在 Flutter 中遍历嵌套的动态 JSON 文件

Powershell 无法从名为 count 的键中获取价值

如何配置spring mvc 3在json响应中不返回null对象?

错误字符串的长度超过了maxJsonLength属性设置的值

在 Bash 中访问 JSON 对象 - 关联数组/列表/另一个模型

Flask 请求和 application/json 内容类型

jQuery fullcalendar 发送自定义参数并使用 JSON 刷新日历

使用杰克逊创建一个 json 对象

区分字符串和列表的 Pythonic 方式是什么?

Retrofit2.0 得到 MalformedJsonException 而 json 似乎正确?

使用适用于 Python 的 Google API - 我从哪里获取 client_secrets.json 文件?

如何在 Python 中合并两个 json 字符串?

严重:找不到媒体类型 = 应用程序/json、类型 = 类 com.jersey.jaxb.Todo、通用类型 = 类 com.jersey.jaxb.Todo 的 MessageBodyWriter

可以在 SharedPreferences 中保存 JSON 数组吗?

确保数组中的项目属性在 Json Schema 中是唯一的?