使用sed

时间:2015-11-15 09:14:02

标签: regex bash unix sed

我正在尝试使用sed更改配置文件中的1个URL,但是由于不同的原因我失败了。 我想要替换的网址是:

#define API_PRODUCTION @"https://api.mything.com/v2.0/services"

with:

#define API_PRODUCTION @"https://qaapp3.mything.com/20151115_apiv2/services"

我尝试在每个/和不同的方法之前使用\来逃避但是未通过"未终止的替代模式"或者为"替代命令中的坏旗:' a'" 似乎很容易,但我不能指出它。 提前谢谢!

2 个答案:

答案 0 :(得分:3)

如果您使用其他字符作为分隔符,则不需要转义/

$ cat testfile
#define API_PRODUCTION @"https://api.mything.com/v2.0/services"
$ sed -e 's,https://api.mything.com/v2.0/services,https://qaapp3.mything.com/20151115_apiv2/services,' testfile
#define API_PRODUCTION @"https://qaapp3.mything.com/20151115_apiv2/services"

答案 1 :(得分:1)

% sed -ie s/api/qapp3/ filename.txt define API_PRODUCTION @"https://qapp3.mything.com/v2.0/services"

我在NetBSD上,所以你的sed可能会有所不同,Pavel。

相关问题