views:

22

answers:

2

I have Cygwin installed, I want to execute something like this on the command prompt:

perl -pne 's/&#60;/<' input > output

But I'm running into two separate issues with the & and < each needing to be escaped.

  • something like 's/&/&' is 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?

+2  A: 

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/&#60;/<
The syntax of the command is incorrect.

Pax> echo s/^&#60;/^<
s/&#60;/</
paxdiablo
Yep yep yep, this is getting me close. Will update with more details, just excited to report that it seems to work. And yes, I know I should just use bash. -- YEP! WORKIE! Thanks!
polygenelubricants
+3  A: 

You are missing the ending slash:

perl -pne 's/&#60;/</' input > output

Since the & and the < are quoted between single quotes, they are not interpreted by the shell.

Sjoerd
Yep, this was also an issue. I needed to escape with `^` at `cmd.exe` as Pax said, and the pattern itself needs the ending slash as you said.
polygenelubricants