【发布时间】:2019-08-06 07:51:49
【问题描述】:
我正在尝试从一些源代码中删除一些 cpp #include 语句。我决定使用名为“sed”的非常棒的实用程序来做到这一点。当我尝试通过以下方式执行“sed.exe”时:
sed -re '/#include \<syslog\.h\>/ d' < syslog.h > changed_syslog.h
sed -re '/#include <syslog\.h>/ d' < syslog.h > changed_syslog.h
我得到错误:
sed: -e expression #1, char 13: unterminated address rege
如果我尝试以下行:
sed -re '/#include .syslog\.h./ d' < syslog.h > changed_syslog.h
然后一切都按预期进行。
现在我想知道我在前两个命令中做错了什么?
我正在使用 Cygwin 1.7.17 中的 sed.exe。
syslog.h 文件如下(只有一行):
#include <syslog.h>
【问题讨论】:
-
不应该是
sed -r '/#include \<syslog\.h\>/d' syslog.h > changed_syslog.h吗? -
@Wiktor Stribiżew -r 代表在脚本中使用扩展的正则表达式,-e 代表将脚本添加到要执行的命令中。我也试过你的命令行,但我得到了同样的错误。
-
我知道
re做了什么。file参数肯定不需要<。e在这里是多余的 -
请注意,
\<和\>表示 sed 中单词的开始/结束,不需要在正则表达式或替换命令的 RHS 中引用<或你用单引号括住 sed 命令。