P0w3rK!d has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I am trying to run this on W2K (unfortunately) and Perl version 5.005_03.
perl -pe 's/FOO/123/g' in.txt > out.txt
where in.txt is:
-a = fuhergrg -b = awerh9w8eh -c = rgiuhreg -d = C:\tmp\FOO.txt
The output of the file never changes. I tried various re's and had no luck. What am I doing wrong here?

Replies are listed 'Best First'.
Re: Search and Replace not working
by Zaxo (Archbishop) on Oct 07, 2002 at 17:50 UTC

    Try perl -pe "s/FOO/123/g" in.txt > out.txt. Winders wants double quotes on the command line.

    After Compline,
    Zaxo

Re: Search and Replace not working
by Helter (Chaplain) on Oct 07, 2002 at 17:52 UTC
    Updated: The shell will getcha every time!

    I can't really offer much help except I just made a file with the contents above and than ran the command line given (without the redirect):
    perl -pe 's/FOO/123/g' blah.txt -a = fuhergrg -b = awerh9w8eh -c = rgiuhreg -d = C:\tmp\123.txt ------------ Contents of blah.txt >more blah.txt -a = fuhergrg -b = awerh9w8eh -c = rgiuhreg -d = C:\tmp\FOO.txt
    As you can see, the FOO changed to 123, is this the ACTUAL code you are trying to run, or have you cleansed it for the site?
Re: Search and Replace not working
by semio (Friar) on Oct 08, 2002 at 03:34 UTC
    UPDATE: Am I imagining things or did I not see the first reply by Zaxo? Anyhow, my apologies.
    Hi P0w3rK!d

    On Win2k, the following one-liner may give you what you're looking for:

    C:\>perl -pe "s/FOO/123/g;" in.txt -a = fuhergrg -b = awerh9w8eh -c = rgiuhreg -d = C:\tmp\123.txt
    Hope this helps.

    cheers, -semio