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.
-
Irrelevant nitpick: less isn't an editor, it's just a pager (a text viewer, if you like).– terdonDec 13, 2017 at 16:26
Add a comment
|
1 Answer
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
??– HISIDec 13, 2017 at 16:29 -
\n
instead of/n
. But that won't work. See here: unix.stackexchange.com/questions/26284/…– pLumoDec 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{
.– terdonDec 13, 2017 at 16:33