我想替换 #Start wp conf
和 #End wp conf
之间的所有内容:
#Start wp conf
<Directory "/home/user/public_html/">
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress_logged_in|wp-postpass_).*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
</Directory>
#End wp conf
我尝试了sed -i -e“s/#Start wp conf.*#End wp conf//g”/root/test-conf
但它没有替换任何内容。
我还尝试了sed -i -e "s/\(#Start wp conf\).*\(#End wp conf\)//g"/root/test-conf
最佳答案
使用 sed
你可以这样做:
sed '/#Start wp conf/,/#End wp conf/d' file
关于regex - Bash 正则表达式替换两个不同字符串之间的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51426129/