Reputation: 1926
I would like to add a comma ,
after the last }
in a shell script.
From:
[
{
"targets": [ "localhost:32804", "localhost:32805" ],
"labels": {
"env": "local",
"job": "instances"
}
}
]
To:
[
{
"targets": [ "localhost:32804", "localhost:32805" ],
"labels": {
"env": "local",
"job": "instances"
}
},
]
Upvotes: 0
Views: 451
Reputation:
Here's one way to do this, with sed
. Using the -z
flag to pretend that lines are terminated by ASCII character 0 (NUL
) rather than newline - so that sed
sees the entire input file as a single long line.
sed -Ez 's/(})([^}]*$)/\1,\2/' <filename>
Upvotes: 1