So I need to be able to inject a value into JSON using sed or awk (preferably on one line) and I cannot install any external libraries to help me.
An example of the json is something like {"version":"0.5363"}
I'd need to be able to inject a new value for version.
Any help would be greatly appreciated.
You could try the below sed command,
$ echo '{"version":"0.5363"}' | sed 's/\({"version":"\)[^"]*\("}\)/\1newvalue\2/g'
{"version":"newvalue"}
In the above sed command, replace the newvalue
with value you want. Add inline edit option -i
to save the changes made.
sed -i 's/regex/replacement/g' file
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.