我將using sed
to insert lines的示例轉換爲特定模式匹配位置的文件。我在我的機器上運行了這個問題的例子,它完美的工作。使用sed插入帶有轉義搜索模式的行
所以,對我來說,特別是,我試圖插入如下:
<Location "someplace">
AuthBasicProvider ldap
AuthType Basic
AuthName "Auth"
AuthLDAPURL someurl
AuthzLDAPAuthoritative on
AuthLDAPBindDN someuser
AuthLDAPBindPassword somepassword
</Location>
我想在.conf文件(this one to be exact)的末尾插入它,具體而言,緊接在結尾</VirtualHost>
前。
然而,當我運行
sed -n 'H;${x;s/\<\/VirtualHost> .*\n/test string &/;p;}' vhost.conf
來測試,該文件的內容被打印但該文件不被改變。我逃脫了</VirtualHost>
錯誤還是錯過了別的東西?
(我也開到了讓我的內容到該文件中其他的解決方案。)
我需要從中學習很多東西(我使用的是BSD)。謝謝! –
快速跟進問題:將上面的大型多行內容放入此答案而不是「測試字符串」中的最佳方式是什麼?我可以想到幾種方法,但都很難看。 –
http://www.grymoire.com/Unix/Sed.html#uh-37 – jshort