正则表达式转义在SED [英] Escaping Regex in SED

查看:369
本文介绍了正则表达式转义在SED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用sed做一个搜索和替换。我将 / **#定义('WP_POST_REVISIONS',3); \\ n \\ n / **#

I need to use Sed to do a search and replace. I'm replacing /**# for define('WP_POST_REVISIONS', 3);\n\n/**#.

但我不能找出正确的转义。甚至逃避(显然需要)单引号后,我还是收到了庆典:附近意外的标记')'语法错误

But I can't figure out the proper escaping. Even after escaping the (obviously needed) single quotes, I still get a bash: syntax error near unexpected token ')'

什么是在这种情况下适当的转义?

推荐答案

尝试更换你的:

find /start/path -name *.html -exec sed -ie 's|/**#|define(\'WP_POST_REVISIONS\', 3);|g' '{}' \;

find /start/path -name '*.html' -print0  \
  | xargs -0 -n 1 sed -ie 's|/\*\*#|define('\''WP_POST_REVISIONS'\'', 3);\n/\*\*#|g'

和告诉我们它给你。

(我想在你的文件(S)猜你要找的实际字符串/ **#......请给我们的例子是你真正需要的,如果它不是实际的字符串)

(I tried to guess you were looking for the actual string "/**#" in your file(s) ... please give us examples of what you are really looking for, if it isn't that actual string)

这篇关于正则表达式转义在SED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆