Reputation: 741
I am trying to replace a boolean inside a JSON string using sed
.
STRING: "should-replace":false
How would I use sed
to replace the false
with true
?
Upvotes: 3
Views: 1571
Reputation: 37394
In awk:
$ awk -F: '/should-replace/{$2=($2=="false"?"true":"false")}1' file
"should-replace" true
Notice: false
-> true
, everything else (meant to mean true
) -> false
.
Upvotes: 1
Reputation: 359
Very straightforward:
sed "s/\"should-replace\":false/\"should-replace\":true/g"
Upvotes: 1