Reputation: 873
I need to edit several files of 500MB or more as follow:
Original file:
{'key_1': true, 'key_2': 1},
{'key_1': true, 'key_2': 3},
...
{'key_1': false, 'key_2': 50},
Result:
[{'key_1': true, 'key_2': 1},
{'key_1': true, 'key_2': 3},
...
{'key_1': false, 'key_2': 50}]
Adding "[" to beginning and changing the last "," for "]".
I want to edit all the *.json files in a folder. Which is the most simple way?
Upvotes: 2
Views: 58
Reputation: 249153
sed -i '1 s/^/[/; $ s/,$/]/' *.json
That is, on the first line, replace the beginning with [
, and on the last line, replace the trailing ,
with ]
.
Upvotes: 5