使用 sed 替换 xml 属性 [英] Using sed to replace xml attribute

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

问题描述

我的文件包含这样一行:

My file contains a line like this:

<virtual-server name="default-host" enable-welcome-root="false">

我想替换:enable-welcom-root 从假到真

I want to replace: enable-welcome-root from false to true

使用 sed -n 's/.*enable-welcome-root="\([^"]*\).*/\1/p' 文件我可以得到 false 的值,但如何替换它?

Using sed -n 's/.*enable-welcome-root="\([^"]*\).*/\1/p' file I can get the value which is false, but how can I replace it?

推荐答案

这将从 falsetrue 更改为 true

This would change from false or true to true

sed -r 's/(enable-welcome-root=")[^"]+"/\1true"/' file
<virtual-server name="default-host" enable-welcome-root="true">

或没有 -r

sed 's/\(enable-welcome-root="\)[^"]+"/\1true"/'
<virtual-server name="default-host" enable-welcome-root="false">

使用-i写回文件

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

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