我有一个配置文件(nginx default.conf),其中有以下类型的字符串:
server {
location / {
proxy_set_header Host sudomain1.somewhere.com;
proxy_pass http://127.0.0.1:8999/;
}
}
server {
location / {
proxy_set_header Host sudomain2.somewhere.com;
proxy_pass http://127.0.0.1:8755/;
}
}
server {
location / {
proxy_set_header Host sudomain3.somewhere.com;
proxy_pass http://127.0.0.1:8525/;
}
}
如何减去有关subdomain2的配置?
server {
location / {
proxy_set_header Host sudomain2.somewhere.com;
proxy_pass http://127.0.0.1:8755/;
}
}
如果可能的话,使用grep会很好!谢谢您的宝贵帮助!
您可以使用以下gnu awk命令subdomain2
通过自定义记录分隔符(RS
)获取块匹配:
awk -v RS='}[[:space:]]*}[[:space:]]*' '/sudomain2/{printf $0 RT}' default.conf
server {
location / {
proxy_set_header Host sudomain2.somewhere.com;
proxy_pass http://127.0.0.1:8755/;
}
}
编辑:打印除subdomain2
使用以外的其他块:
awk -v RS='}[[:space:]]*}[[:space:]]*' '!/sudomain2/{printf $0 RT}' file
server {
location / {
proxy_set_header Host sudomain1.somewhere.com;
proxy_pass http://127.0.0.1:8999/;
}
}
server {
location / {
proxy_set_header Host sudomain3.somewhere.com;
proxy_pass http://127.0.0.1:8525/;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句