简体   繁体   中英

Using 'sed' on a JSON file to find and replace

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

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

For example if the json looks like

{"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"}}}

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

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

Tried it locally and it seemed to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM