使用JQ - 拆分和修改后连接记录
我有一个数组,其中一些记录需要重复。 id 值可能是 2 个字符串通过“;”连接,如下
{"_time": "2022-02-20T23","csp_name": "1","tool_bf_id": "1234", " id":"aa-1111;aa-2222"}
或 id 值为 null 或只有 1 个引用:
{"_time": "2022-02-20T23","csp_name": "3","tool_bf_id": "1357", "dvc_ssr": "null"}
{"_time": "2022-02-20T23","csp_name": "4","tool_bf_id": "2468", "dvc_ssr": "aa-3333"}
我能够复制此记录并且得到以下内容:
{"_time": "2022-02-20T23","csp_name": "1","tool_bf_id": "1234", "dvc_ssr": "aa-1111","id":"aa-1111;aa-2222"},
{"_time": "2022-02-20T23","csp_name": "1","tool_bf_id": "1234", "dvc_ssr": "aa-2222","id":"aa-1111;aa-2222"}
感谢另一篇文章: 使用公用密钥加入 2 个文件
我通过加入另一个文件中的数据来修改我的记录:
{"_time":"2022-02-20T23","csp_name":"1","tool_bf_id":"1234","id":"aa-1111;aa-2222", "dvc_ssr":"aa-1111","host":"hostId1"}
,{"_time":"2022-02-20T23","csp_name":"1","tool_bf_id":"1234","id":"aa-1111;aa-2222","dvc_ssr":"aa-2222","host":"hostId2"}
现在我需要合并记录返回并加入新添加字段(大约 10 个)中的值
{"_time": "2022-02-20T23","csp_name": "1","tool_bf_id": "1234", "id ":"aa-1111;aa-2222", "主机": "hostId1;hostId2"}
I have an array where some records need to be duplicated. The id value might be a join of 2 string by ";", as below
{"_time": "2022-02-20T23","csp_name": "1","tool_bf_id": "1234", "id":"aa-1111;aa-2222"}
or id value is null or only 1 ref:
{"_time": "2022-02-20T23","csp_name": "3","tool_bf_id": "1357", "dvc_ssr": "null"}
{"_time": "2022-02-20T23","csp_name": "4","tool_bf_id": "2468", "dvc_ssr": "aa-3333"}
I am able to duplicate this record and get the following:
{"_time": "2022-02-20T23","csp_name": "1","tool_bf_id": "1234", "dvc_ssr": "aa-1111","id":"aa-1111;aa-2222"},
{"_time": "2022-02-20T23","csp_name": "1","tool_bf_id": "1234", "dvc_ssr": "aa-2222","id":"aa-1111;aa-2222"}
Thanks to another post: Join 2 files using a common key
I modify my records by joining data from another file:
{"_time":"2022-02-20T23","csp_name":"1","tool_bf_id":"1234","id":"aa-1111;aa-2222", "dvc_ssr":"aa-1111","host":"hostId1"}
,{"_time":"2022-02-20T23","csp_name":"1","tool_bf_id":"1234","id":"aa-1111;aa-2222","dvc_ssr":"aa-2222","host":"hostId2"}
Now I need to merge the records back and join the value from the new added fields (which are around 10)
{"_time": "2022-02-20T23","csp_name": "1","tool_bf_id": "1234", "id":"aa-1111;aa-2222", "host": "hostId1;hostId2"}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
hosts.jsonl
:records.jsonl
:输出:
演示< /a> 在 jqplay 上
hosts.jsonl
:records.jsonl
:Output:
Demo on jqplay