【问题标题】:Recursive Search and replace with / and '递归搜索并用 / 和 ' 替换
【发布时间】:2012-08-24 04:11:45
【问题描述】:

我已经搜索并没有找到解决方案,如果之前已经回答过,我很抱歉,我不擅长 shell。

我正在尝试通过 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

但我认为它不起作用,因为斜线和单引号。我试过用\ 转义这些,但无济于事,有什么想法吗?

【问题讨论】:

  • ssh 和这个有什么关系?

标签: perl shell unix replace xargs


【解决方案1】:

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;

【讨论】:

  • 非常感谢艾伦的有用回答
猜你喜欢
  • 1970-01-01
  • 2010-11-07
  • 1970-01-01
  • 2011-01-07
  • 1970-01-01
  • 2012-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多