Busyboxユーティリティを使用してファイルの最後の文字の前にコンテンツを追加するにはどうすればよいですか?
内容を含むファイルがあります。 { "first_name": "John", "last_name": "Smith", "is_alive": true, "age": 27, "address": { "street_address": "21 2nd Street", "city": "New York", "state": "NY", "postal_code": "10021-3100" }, "phone_numbers": [ { "type": "home", "number": "212 555-1234" }, { "type": "office", "number": "646 555-4567" } ], "children": [ "Catherine", "Thomas", "Trevor" ], "spouse": null } ファイルの内容が次のように表示されるように、Busyboxユーティリティを使用してファイルの最後の文字の前に内容を追加するにはどうすればよいですか。 { "first_name": "John", "last_name": "Smith", "is_alive": true, "age": 27, "address": { "street_address": "21 2nd Street", "city": "New York", "state": "NY", "postal_code": "10021-3100" }, "phone_numbers": [ { "type": "home", "number": "212 555-1234" }, { "type": "office", "number": "646 555-4567" } ], "children": [ "Catherine", "Thomas", "Trevor" ], "spouse": null, "field1": "value1", "field2": "value2", "field3": "value3", "field4": "value4" } ただし、}文字が必ずしもファイルの最後の文字または最後の行にある必要はありません。 これまで私はこの解決策を見つけました。 tac file2 | sed '0,/}/s/}/}\n"field4": "value4"\n"field3": "value3",\n"field2": "value2",\n"field1": "value1",\n,/' | tac>tmp_file && mv tmp_file file2