2012-08-29 81 views
0

替換我已經搜索並找不到解決方案,所以很抱歉,如果之前已經回答了這個問題,我並不擅長搜索。遞歸搜索並用/和'

我想做一個遞歸搜索,並通過SSH替換所有文件。

到目前爲止,我有這樣的:

find . -type f | xargs -d "\n" perl -pi -e 's/$this->helper('catalog/product')->getPriceHtml/$this->getPriceHtml/g' 

我試圖取代這個:

$this->helper('catalog/product')->getPriceHtml 

與此:

$this->getPriceHtml 

但我認爲它不工作因爲斜槓和單引號。我試圖用\逃脫這些,但無濟於事,有什麼想法?

+2

是什麼SSH與此有關呢? – geoffspear

回答

2

s運營商的備用分隔符可用於避免柵欄柵欄$this將被視爲一個變量,除非$被轉義。括號也必須逃脫。否則他們組成一個捕獲組。由於它是一行內容,報價已用盡,單引號已使用十六進制轉義編碼。下面應該工作:

s{\$this->helper\(\x{27}catalog/product\x{27}\)->getPriceHtml}{\$this->getPriceHtml}g; 

或者:

s{(?<=\$this)->helper\(\x{27}catalog/product\x{27}\)(?=->getPriceHtml)}{}g; 
+1

非常感謝您的有用答案Alan – user1633416

+0

不客氣。 :-) –