I am trying to remove some cpp #include statement from some source code. I decided to do this with very great utility called "sed". When I try to execute "sed.exe" in the following ways:
sed -re '/#include \<syslog\.h\>/ d' < syslog.h > changed_syslog.h
sed -re '/#include <syslog\.h>/ d' < syslog.h > changed_syslog.h
I get error:
sed: -e expression #1, char 13: unterminated address rege
If I try the following line:
sed -re '/#include .syslog\.h./ d' < syslog.h > changed_syslog.h
then everything works as expected.
Now what I want to know is what am I doing wrong in the first two commands?
I am using sed.exe from Cygwin 1.7.17.
syslog.h file looks in the following way (only one line):
#include <syslog.h>
sed
is complaining that the 'address regular expression' is unterminated. The address regular expression is /#include \<syslog\.h\>/
, so this implies that sed
isn't seeing the final /
.
In this case, the problem is that the the Windows shell is treating the <
and >
characters in <syslog\.h>
as redirects. The solution is to quote them using ^
:
sed -re '/#include ^<syslog\.h^>/ d'