I need to concatenate multiple JSON files, so
...
"tag" : "description"
}
]
[
{
"tag" : "description"
...
into this :
...
"tag" : "description"
},
{
"tag" : "description"
...
So I need to replace the pattern ] [ with ,, but the new line character makes me crazy...
I used several methods, I list some of them:
sed
sed -i '/]/,/[/{s/./,/g}' file.jsonbut I get this error:
sed: -e expression #1, char 16: unterminated address regexI tried to delete all the newlines following this example
sed -i ':a;N;$!ba;s/\n/ /g' file.jsonand the output file has "^M". Although I modified this file in unix, I used the dos2unix command on this file but nothing happens. I tried then to include the special character "^M" on the search but with worse results
Perl (as proposed here)
perl -i -0pe 's/]\n[/\n,/' file.jsonbut I get this error:
Unmatched [ in regex; marked by <-- HERE in m/]\n[ <-- HERE / at -e line 1.