Home > Enterprise >  sed does not edit my file, i want add a comma at every line
sed does not edit my file, i want add a comma at every line

Time:06-13

I want add a comma at every line in a big JSON file.

I am gonna use the 'sed' command.

I do a test with this file (test.json) :

[
{"test" : "test"}
{"test": "test"}]

I do : sed "$!s/$/,/" test.json

the console return :

[,
{"test" : "test"},
{"test": "test"}],

(so this is what I want)

But my file did not change

CodePudding user response:

You need to use -i option to make the changes directly in the file (if you do so, I recommend creating backup)

The following command should do, what you want

sed -i 's/$/,/' test.json

You can create backup by providing suffix after the -i option -i[SUFFIX]

The following command will create test.json.bak file with original contents and apply changes to test.json

sed -i.bak 's/$/,/' test.json
  • Related