【问题标题】:Combine output of jq onto single line per record output将 jq 的输出组合到每条记录输出的单行上
【发布时间】:2020-09-30 11:09:29
【问题描述】:

我目前有来自jq 的输出,如下所示:

1§
{"id":"1","name":"River Street , Clerkenwell","lastUpdate":"1601461560941"}
2§
{"id":"2","name":"Phillimore Gardens, Kensington","lastUpdate":"1601461560941"}

我希望它加入每条记录的输出行,即:

1§{"id":"1","name":"River Street , Clerkenwell","lastUpdate":"1601461560941"}
2§{"id":"2","name":"Phillimore Gardens, Kensington","lastUpdate":"1601461560941"}

这是示例输入和当前过滤器:https://jqplay.org/s/qBfGyriA5B

如果我使用-j,那么我将所有内容都放在同一行,这不是我想要的

1§{"id":"1","name":"River Street , Clerkenwell","lastUpdate":"1601461560941"}2§{"id":"2","name":"Phillimore Gardens, Kensington","lastUpdate":"1601461560941"}

【问题讨论】:

    标签: jq


    【解决方案1】:

    一种方法是在创建的对象上通过空字符串使用join 函数。请注意,您正在创建的对象需要转换为字符串类型才能工作。在--raw-output/-r 模式下使用下面的过滤器

    .stations.station[] + { lastUpdate: .stations."@lastUpdate" } | 
    [ .id + "§", tostring ] | 
    join("")
    

    jqplay demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-05
      • 1970-01-01
      • 1970-01-01
      • 2016-07-27
      • 1970-01-01
      • 2013-11-03
      • 2017-03-16
      • 1970-01-01
      相关资源
      最近更新 更多