[英]How to work with “/” using sed in shell script
I am trying to replace a line in my .xml file using a shell script (working on MAC OSX). 我正在尝试使用外壳程序脚本(在MAC OSX上运行)替换.xml文件中的一行。 Problem is: I want to change a tag
<source-path>/Users/myouser</source-path>
to <source-path>/Users/otherUser</source-path>
I am having two problems: 问题是:我想将标签
<source-path>/Users/myouser</source-path>
更改为<source-path>/Users/otherUser</source-path>
我遇到两个问题:
1) How can I handle with "/" using sed? 1)如何使用sed处理“ /”? 2) Can I use regular expression?
2)我可以使用正则表达式吗?
Thanks 谢谢
The simplest answers is to use a different delimiter in your expression, eg: 最简单的答案是在表达式中使用其他定界符,例如:
sed -e 's|/Users/myouser|/Users/otherUser|' file.xml
As to whether you can use regular expressions -- you're using sed
, so yes. 至于是否可以使用正则表达式-您正在使用
sed
,所以可以。
Standard disclaimer that modifying XML with sed is a fragile and error-prone approach. 使用免责声明修改XML的标准免责声明是一种脆弱且容易出错的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.