使用sed或awk查找并替换JSON [英] Find and replace for JSON with sed or awk

查看:534
本文介绍了使用sed或awk查找并替换JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我需要能够使用sed或awk(最好在一行中)将值注入JSON,并且我无法安装任何外部库来帮助我.

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.

json的示例类似于{"version":"0.5363"}

An example of the json is something like {"version":"0.5363"}

我需要能够为版本注入新的值.

I'd need to be able to inject a new value for version.

任何帮助将不胜感激.

推荐答案

您可以尝试以下sed命令,

You could try the below sed command,

$ echo '{"version":"0.5363"}' | sed 's/\({"version":"\)[^"]*\("}\)/\1newvalue\2/g'
{"version":"newvalue"}

在上面的sed命令中,将newvalue替换为所需的值.添加内联编辑选项-i以保存所做的更改.

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

这篇关于使用sed或awk查找并替换JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆