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.
Asked
Active
Viewed 5,317 times
1
-
Irrelevant nitpick: less isn't an editor, it's just a pager (a text viewer, if you like). – terdon Dec 13 '17 at 16:26
1 Answers
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
-
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