我有一个文件,其中每行是一个JSON对象:
{"index":{}}
{"msg_text":"yes","@timestamp":"2019-03-31T00:01:59.574Z","o_error":"INTERNAL_INVALID_MESSAGE","sender":"353830465174","account_id":"e15965cf-ffc1-40ae-94c4-b450ab190222","recipient":"49223","@version":1,"submission_ts":1553990519574000,"delivery_ts":1553990519574000}
{"index":{}}
{"msg_text":"yes","@timestamp":"2019-03-31T00:01:59.574Z","o_error":"INTERNAL_INVALID_MESSAGE","sender":"353830478555","account_id":"e15965cf-ffc1-40ae-94c4-b450ab190222","recipient":"49223","@version":1,"submission_ts":1553990519574000,"delivery_ts":1553990519575000}
{"index":{}}
我想删除所有的delivery_ts
字段和值。下面就是我想要的:
{"index":{}}
{"msg_text":"yes","@timestamp":"2019-03-31T00:01:59.574Z","o_error":"INTERNAL_INVALID_MESSAGE","sender":"353830465174","account_id":"e15965cf-ffc1-40ae-94c4-b450ab190222","recipient":"49223","@version":1,"submission_ts":1553990519574000}
{"index":{}}
{"msg_text":"yes","@timestamp":"2019-03-31T00:01:59.574Z","o_error":"INTERNAL_INVALID_MESSAGE","sender":"353830478555","account_id":"e15965cf-ffc1-40ae-94c4-b450ab190222","recipient":"49223","@version":1,"submission_ts":1553990519574000}
{"index":{}}
如何使用Linux命令执行此操作?
编辑JSON是jq
存在的目的。
jq -c 'del(.delivery_ts)' <in.json >out.json
请在https://jqplay.org/s/v1-J5cTMA-
查看与您指定的输入对应的运行情况。