【问题标题】:print values of a specific key from a json file using a command line in terminal [closed]使用终端中的命令行从 json 文件中打印特定键的值 [关闭]
【发布时间】:2021-02-12 14:41:54
【问题描述】:

如何使用sedjq 递归打印我的json 文件中所有条目的ts 键的值。 一个条目示例:

jsondata = {"text":"/home/ubuntu/processed/00","meta":{"file":"/home/ubuntu/processed/00.03.2019/frames/BR_3.23.1_input_1_A/BR_3.23.1_input_1_A_s0_f004080.jpg","path":"/home/ubuntu/processed/00.03.2019/frames/BR_3.23.1_input_1_A/BR_3.23.1_input_1_A_s0_f004080.jpg"},"options":[{"id":1,"text":"Yes"},{"id":2,"text":"No"}],"_input_hash":-1054720619,"_task_hash":-622956281,"_session_id":"GN","_view_id":"blocks","width":1920,"height":1088,"spans":[{"id":"f19c5f90-b4ea-402b-b350-eb4a177a01d7","label":"person","color":"yellow","x":910.3,"y":213.8,"height":644.8,"width":252,"center":[1036.3,536.2],"type":"rect","points":[[910.3,213.8],[910.3,858.6],[1162.3,858.6],[1162.3,213.8]]}],"answer":"accept","ts":"2021-02-09-15"}

【问题讨论】:

    标签: linux sed grep


    【解决方案1】:

    我猜你想打印与键关联的值,而不是键本身。

    使用,可以指定.ts来选择顶层对象的时间戳。 -r 选项打印“原始”值,即不带双引号:

    jq -r '.ts' file.json
    

    【讨论】:

      猜你喜欢
      • 2021-10-23
      • 2015-10-21
      • 2022-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-14
      相关资源
      最近更新 更多