1

I have a json file that it has more than 30k lines, and I need to replace all instances of }{ in the file with },{ by using script shell or just a text editor like less or vim.

terdon
  • 100,812
HISI
  • 231

1 Answers1

3

Just use sed:

sed 's/}{/},{/g' orig.json > new.json

Or, to edit the file in place (this will copy the original to orig.json.bak):

sed -i.bak 's/}{/},{/g' orig.json
dessert
  • 39,982
terdon
  • 100,812
  • If there is a return line between } and {, should I put sed 's/}/n{/},{/g' orig.json > new.json ?? – HISI Dec 13 '17 at 16:29
  • \n instead of /n. But that won't work. See here: https://unix.stackexchange.com/questions/26284/how-can-i-use-sed-to-replace-a-multi-line-string – pLumo Dec 13 '17 at 16:33
  • 1
    @YassineSihi no, if there's a return line then you are asking for something completely different and that won't work. That's why you shjould always include examples when asking this sort of question. }{ is not the same as } { and not the same as }\n{ or }\t{. – terdon Dec 13 '17 at 16:33