在JSON文件上使用'sed'来查找和替换

时间:2016-02-03 01:15:39

标签: json regex unix sed

我正在尝试使用sed在另一个组错误转换的json文件中将null替换为> \u00018øÏùÄ。但是sed似乎没有做任何事情

sed -i 's|B\u001eøøïùÄ|null|g' 02_20060711_002_2.json

例如,如果json看起来像

{"my_log (PA1)": {"test_number_n": "3999999", "timestamp_log": "04:28:21.218", "trans_blah_i": "0", "record_test_type": {"sequence_nbr_u": "999"}, "filler_2_s": "", "dd": {"ty": {"ex_user_code": {"country_id_s": "", "user_id_s": "", "filed2": ""}, "whose": {"testing_code": {"city_id_s": "", "user_id_s": "", "fggstomer_s": ""}, "ex_client_s": "", "filler_2_s": ""}, "series": {"ticket_c": "0", "strike_test_i": "0", "can_n": "0", "country_c": "0", "instrument_group_c": "0", "expiration_date_n": "0", "modifier_c": "0"}, "exchange_info_s": "", "customer_info_s": "B\u001eøøïùÄ", "onu": "34", "ak": "0", "trading_code": {"city_id_s": "jk", "user_id_s": "O05", "ex_cur_s": "21  "}}, "timestamp_in_q": "03:28:21.217"}}}

1 个答案:

答案 0 :(得分:1)

您需要在sed命令中转义反斜杠。 试试这个:

sed -i 's|B\\u001eøøïùÄ|null|g' 02_20060711_002_2.json

在当地尝试,似乎有效。