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

时间:2021-03-03 19:31:30

I'm trying to use sed to replace >\u00018øÏùÄ with null in a json file that was converted incorrectly by another group. But sed doesn't seem to do anything

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

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

For example if the json looks like

例如,如果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 个解决方案

#1


1  

You need to escape the backslash in your sed command. Try this:

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

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

Tried it locally and it seemed to work.

在当地尝试它似乎工作。

#1


1  

You need to escape the backslash in your sed command. Try this:

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

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

Tried it locally and it seemed to work.

在当地尝试它似乎工作。