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.txtThis 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?
1 Answer1
I am not sure why, but using double quote instead of single makes it work.
perl -pi.bak -e "s/doing/feeling/g" Test1.txt3 Comments
cmd.exe doesn't treat single quotes as string delimiters. There's a good explanation in the accepted answer to the question I linked above.Explore related questions
See similar questions with these tags.


