Replace all < with < with perl on cygwin
I have Cygwin installed, I want to execute something like this on the command prompt:
perl -pne 's/</<' input > output
But I'm running into two separate issues with the &
and <
each needing to be escaped.
- something like
's/&/&'
i开发者_运维问答s an error at the perl level- "Substitution pattern not terminated at -e line 1"
- something like
's/</<'
is an error at the shell level- "The system cannot find the file specified."
What do I have to do to fix this?
You are missing the ending slash:
perl -pne 's/</</' input > output
Since the & and the < are quoted between single quotes, they are not interpreted by the shell.
Seriously, if you have CygWin installed, you should be doing everything from bash
, not cmd.exe
. It has much more capability when it comes to processing and escaping command line arguments.
Having said that, you may try to use the ^
escape character. That's the standard one for cmd.exe
and it may allow you to at least get rid of the problem with <
:
Pax> echo <
The syntax of the command is incorrect.
Pax> echo ^<
<
I haven't tried this since I don't have Perl installed on my local Windows VM. I do have CygWin on the laptop but, as I said, I tend to use bash
there instead of cmd.exe
. So all care and no responsibility on this answer :-)
Pax> echo s/</<
The syntax of the command is incorrect.
Pax> echo s/^</^<
s/</</
精彩评论