如何在jq中对字段值进行多次分配? [英] How to make multiple assignment of field values in jq?

查看:37
本文介绍了如何在jq中对字段值进行多次分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的jq命令:

jq --arg ts "$TS" '.Date = $ts, .Marker.Date = $ts, .InfoFromTerminator.Timestamp = $ts'

,但它似乎仅替换最后一项,而使前两项保持原样.如何重写查询以替换所有3个参数?

but it appears to only replace the last item keeping the previous two as is. How do I rewrite the query to replace for all 3 parameters?

推荐答案

逗号是jq中的运算符:

即使逗号运算符是生成器,也将首先生成值 由逗号左侧的表达式生成,然后针对每个 这些值是由右边的表达式生成的 逗号.

Even the comma operator is a generator, generating first the values generated by the expression to the left of the comma, then for each of those, the values generate by the expression on the right of the comma.

更改多个元素可以通过以下方式从一个过滤器/分配到下一个过滤器/分配的管道传输来完成:

Changing multiple elements can be done by piping from one filter/assignment in to the next as follows:

jq --arg ts "$TS" '.Date = $ts | .Marker.Date = $ts | .InfoFromTerminator.Timestamp = $ts'

这篇关于如何在jq中对字段值进行多次分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆