我一直在使用grep命令搜索文件中的内容,以下是命令及其输出:
grep -i -A4 -B5 -w "servername.*xyz" httpd.conf.webserver.apache22.orig
<VirtualHost *>
ServerAdmin errorhelp@xyz.com
DocumentRoot "/opt/xyz/www"
DirectoryIndex error.html
ErrorDocument 404 /error.html
ServerName email-xyz.com
ProxyRequests off
ProxyPass / http://localhost/ui/pages/companies/xyz/
ProxyPassReverse / http://localhost/ui/pages/companies/xyz/
</VirtualHost>
--
<VirtualHost *>
ServerAdmin errorhelp@xyz.com
DocumentRoot "/opt/xyz/www"
DirectoryIndex error.html
ErrorDocument 404 /error.html
ServerName xyz.p.com
ProxyRequests off
ProxyPass / http://localhost/ui/pages/companies/xyz/
ProxyPassReverse / http://localhost/ui/pages/companies/xyz/
</VirtualHost>
有人能建议我如何永久地从一个文件中删除两个节的内容吗?
下面是我尝试过的方法,有人能告诉我我的错误吗?
sed -i "/`grep -i -A4 -B5 -w "servername.*xyz" httpd.conf.webserver.apache22.orig`/d" httpd.conf.webserver.apache22.orig
在后台没有执行执行内容并将其传递给sed编辑器的工作。
发布于 2015-08-30 03:03:47
您可以使用空RS
尝试这个gnu-awk。
awk -v RS= -v ORS='\n\n' -v IGNORECASE=1 '!/ServerName[[:space:]]+.*xyz/' httpd.conf.webserver.apache22.orig
RS=
将在一条记录中创建整个<VirtualHost...</VirtualHost>
块,使用!/ServerName[[:space:]]+.*xyz/
,我们可以在输出中否定搜索结果。
https://stackoverflow.com/questions/32295591
复制