0

I have a file with the following contents

$(CP) "$(O_SSL)" "$(INSTALLTOP)\bin"
$(CP) "$(O_CRYPTO)" "$(INSTALLTOP)\bin"

I want to add the following lines (order doesn't matter)

$(CP) "$(SSL).pdb" "$(INSTALLTOP)\bin"
$(CP) "$(CRYPTO).pdb" "$(INSTALLTOP)\bin"

So, using perl, I created the following command (which must be run from the command prompt):

perl -pi.bak -e 's#\t\$\(CP\) "\$\(O_([^)]+)\)" "\$\(INSTALLTOP\)\\bin"#$&\n\t\$(CP) "\$($1).pdb" "\$(INSTALLTOP)\\bin#g' ntdll.mak

But I just get the following error

Can't find string terminator "'" anywhere before EOF at -e line 1.
The system cannot find the path specified.

I tried replacing the single quotes with double quotes (and doubling all internal doublequotes) as so

perl -pi.bak -e "s#\t\$\(CP\) ""\$\(O_([^)]+)\)"" ""\$\(INSTALLTOP\)\\bin""#$&\n\t\$(CP) ""\$($1).pdb"" ""\$(INSTALLTOP)\\bin""#g" ntdll.mak

but I just get the following error instead

Substitution pattern not terminated at -e line 1.

How should I do this? (... I don't want to create a separate script file, but I'll do it if there's no other (reasonable) way)

Bwmat
  • 4,314
  • 3
  • 27
  • 42
  • Look into this [quotemeta](http://perldoc.perl.org/functions/quotemeta.html), May be this could solve your problem! – AbhiNickz Mar 07 '17 at 07:02
  • Possible duplicate of [How do I escape special chars in a string I interpolate into a Perl regex?](http://stackoverflow.com/questions/2156731/how-do-i-escape-special-chars-in-a-string-i-interpolate-into-a-perl-regex) – AbhiNickz Mar 07 '17 at 07:02

1 Answers1

1

I worked around the problem by using octal escapes for literal doublequotes

perl -pi.bak -e "s#\t\$\(CP\) \042\$\(O_([^)]+)\)\042 \042\$\(INSTALLTOP\)\\bin\042#$&\n\t\$(CP) \042\$(LIB_D)\\\$($1).pdb\042 \042\$(INSTALLTOP)\\bin\042#g" ntdll.mak
Bwmat
  • 4,314
  • 3
  • 27
  • 42