Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strawberry Perl regular expression, Windows 7 [duplicate]

Tags:

regex

perl

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?

like image 341
Drew Rush Avatar asked Dec 10 '25 19:12

Drew Rush


1 Answers

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
like image 80
Sabuj Hassan Avatar answered Dec 12 '25 14:12

Sabuj Hassan