[英]regex with sed shell script
I have a problem when I'm trying to regex a line in a document with sed. 当我尝试使用sed对文档中的行进行正则表达式时遇到问题。 Here is what I want to regex:
这是我要正则表达式的内容:
proxy_pass http:\\\\193.168.19.35/;
proxy_pass http:\\\\ 193.168.19.35/;
I want to obtain the following result: 我想获得以下结果:
proxy_pass http:\\\\193.168.19.32/;
proxy_pass http:\\\\ 193.168.19.32/;
This is what I have tried: 这是我尝试过的:
sed -r 's/^proxy_pass htpp\:\/\/[[:digit:]]+.*\/;/proxy_pass htpp\:\/\/192.168.81.29\/;/' /etc/nginx/nginx.conf > /etc/nginx/nginx.conf.temp
Can you guys help me here? 你们能帮我吗?
If you have a URL with \\\\
, you need to add support for this pattern in your regex. 如果您的网址带有
\\\\
,则需要在正则表达式中添加对此模式的支持。 I believe you just misspelt some words in your question. 我相信您只是在问题中遗漏了一些单词。
So, if you want to match proxy_pass http:\\\\193.168.19.32/;
因此,如果要匹配
proxy_pass http:\\\\193.168.19.32/;
, use , 采用
sed -r 's/^proxy_pass http\:\\\\[[:digit:]]+(\.[[:digit:]]+)*\/;/proxy_pass htpp\:\/\/192.168.81.29\/;/' /etc/nginx/nginx.conf > /etc/nginx/nginx.conf.temp
^^^^ |---------------|
If you want to replace proxy_pass http://193.168.19.32/;
如果要替换
proxy_pass http://193.168.19.32/;
, use , 采用
sed -r 's/^proxy_pass http\:\/\/[[:digit:]]+(\.[[:digit:]]+)*\/;/proxy_pass htpp\:\/\/192.168.81.29\/;/' /etc/nginx/nginx.conf > /etc/nginx/nginx.conf.temp
^ ^ |---------------|
Pay attention to (\\.[[:digit:]]+)*
in the pattern, it makes it possible to match all the 4 parts of the IP address. 注意模式中的
(\\.[[:digit:]]+)*
,它可以匹配IP地址的所有4个部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.