3

I'm trying to execute a simple search and replace at the command line.

I have a file called Test1.txt. The contents are "How are you doing today?"

At the command line, I have navigated to the folder in which the text file resides: C:\perl.

Here are the commands I've issued and the results/messages I'm getting:

perl -pi.bak -e 's/doing/feeling/g' Test1.txt

This creates the backup, but no observable change is made to Test1.txt even though it appears the file was modified as far as Windows explorer is concerned.

perl -pi.bak -e "BEGIN{@ARGV=<Test1.txt>} s/doing/feeling/g"

This makes the change and creates the backup, but I get the message:

-i used with no filenames on the command line, reading from STDIN

Is there a way to use -i with filenames on the command line? I found the BEGIN syntax elsewhere as the way to do it in Windows, but is there no other way to do it without getting this message?

Peter Mortensen's user avatar
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
askedDec 20, 2013 at 21:25
Drew Rush's user avatar
0

1 Answer1

3

I am not sure why, but using double quote instead of single makes it work.

perl -pi.bak -e "s/doing/feeling/g" Test1.txt
Peter Mortensen's user avatar
Peter Mortensen
31.4k22 gold badges110 silver badges134 bronze badges
answeredDec 20, 2013 at 21:41
Sabuj Hassan's user avatar
Sign up to request clarification or add additional context in comments.

3 Comments

From what I've read, double quotes means interpret while single quotes means do not. Not sure what the difference is in this context, however.
@DrewRushcmd.exe doesn't treat single quotes as string delimiters. There's a good explanation in the accepted answer to the question I linked above.
For the gory details of dealing command-line parameters to cmd.exe and other Windows executables, seeA Better Way To Understand Quoting and Escaping of Windows Command Line Arguments and the follow-up postHow a Windows Program Splits Its Command Line Into Individual Arguments.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.