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.

1
  • Irrelevant nitpick: less isn't an editor, it's just a pager (a text viewer, if you like).
    – terdon
    Dec 13, 2017 at 16:26

1 Answer 1

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
3
  • If there is a return line between } and {, should I put sed 's/}/n{/},{/g' orig.json > new.json ??
    – HISI
    Dec 13, 2017 at 16:29
  • \n instead of /n. But that won't work. See here: unix.stackexchange.com/questions/26284/…
    – pLumo
    Dec 13, 2017 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, 2017 at 16:33

Not the answer you're looking for? Browse other questions tagged .