我有一个 JSON 文件,其中包含以下格式的数据。我正在为德鲁伊写索引任务来摄取数据。它因时间戳 (event_time) 而拒绝。
有没有办法将 event_time 值从 2016-11-30 23:59:53.654000 转换为 2016-11-30T23:59:53.654Z?
JSON 文件:
{"app":14232,"device_carrier":"airtel","$schema":10,"city":"Bellary","user_id":"234293","uuid":"1d5b5328 -b729-11e2-a0e5-22340a56812f","event_time":"2016-11-30 23:59:53.654000","platform":"Android","os_version":"4.4.2","insider_id":3426766963 "processed_time":"2016-12-01 00:00:05.429064","user_creation_time":"2015-12-14 18:34:04.632000","version_name":"2.08","ip_address":"117.266. 132.112","paying":"true","dma":null,"user_properties":{[SauceFlyer] campaign":"N\/A",[SauceFlyer] media source":"Chemical"},"client_upload_time":"2016-12-01 00:00:03.982000","$insert_id":"e43b2a4d-072f-2322-bd74-6bdb0b2e1f63","event_type":"Search","library":"insider-android\/2.9.2","device_type":"Micromax Owen Nitro","device_manufacturer":"Micromax","start_version":"1.57","location_lng":null,"server_upload_time":"2016-12-01 00: 00:04.230000","event_id":286,"location_lat":null,"os_name":"android","insider_event_type":null,"device_brand":"Micromax","groups":{},"event_properties": {“搜索查询”:“离合器s for women"},"data":{},"device_id":"ff71c4f0-81b8-4a44-8db1-1555e22f6761R","language":"English","device_model":"Micromax A310","country": "India","region":"Karnataka","adid":null,"session_id":1480550372776,"device_family":"Micromax Phone","idfa":null,"client_event_time":"2016-11-30 23 :59:53.406000"}
最佳答案
sed 的另一种方法(因为年、月、日、小时、分钟和秒不仅是 [0-9]
数字):
$ sed 's/\([12][0-9]\{3\}-[01][0-9]-[0-3][0-9]\) \([0-2][0-9]\(:[0-5][0-9]\)\{2\}\.[0-9]\{3\}\)000/\1T\2Z/' <<< "2016-11-30 23:59:53.654000"
2016-11-30T23:59:53.654Z
关于regex - 在文件中替换/插入时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41973884/