Bash正则表达式替换两个不同字符串之间的所有内容

时间:2018-07-19 15:08:52

标签: regex bash

我要替换#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,但是它没有替代任何东西。

我也尝试过<textarea>

1 个答案:

答案 0 :(得分:2)

使用sed,您可以这样做:

sed '/#Start wp conf/,/#End wp conf/d' file