D
Dominic Philsby
Hi, I'm using Perl to do simple text search & replace within a text
file. The Perl version, sample file, and commandline syntax I am using
is shown below.
C:\test>
C:\test>
C:\test>type file.txt
the quick brown cow jumps over the lazy horse
C:\test>
C:\test>
C:\test>perl -p -e "s/cow/fox/g;s/horse/dog/g" file.txt
the quick brown fox jumps over the lazy dog
C:\test>
C:\test>
C:\test>perl -v
This is perl, v5.6.1 built for MSWin32-x86
Copyright 1987-2001, Larry Wall
Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source
kit.
Complete documentation for Perl, including FAQ lists, should be found
on
this system using `man perl' or `perldoc perl'. If you have access to
the
Internet, point your browser at http://www.perl.com/, the Perl Home
Page.
C:\test>
C:\test>
C:\test>
My file.txt document contains only one line but the real files are
several hundred thousand lines.
The words I am changing are not just "cow" and "horse" but hundreds of
words.
I am using Windows.
In my commandline program, my question is rather than specifying "s/
cow/fox/g;s/horse/dog/g" on the commandline, I want to reference a
file containing this. In otherwords, I want my commandline program to
reference a text file, lets call it regexReplace.txt, containing the
following
s/cow/fox/g;
s/horse/dog/g;
Can someone help me out with the syntax or how to do this?
Thank you
Dominic
file. The Perl version, sample file, and commandline syntax I am using
is shown below.
C:\test>
C:\test>
C:\test>type file.txt
the quick brown cow jumps over the lazy horse
C:\test>
C:\test>
C:\test>perl -p -e "s/cow/fox/g;s/horse/dog/g" file.txt
the quick brown fox jumps over the lazy dog
C:\test>
C:\test>
C:\test>perl -v
This is perl, v5.6.1 built for MSWin32-x86
Copyright 1987-2001, Larry Wall
Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source
kit.
Complete documentation for Perl, including FAQ lists, should be found
on
this system using `man perl' or `perldoc perl'. If you have access to
the
Internet, point your browser at http://www.perl.com/, the Perl Home
Page.
C:\test>
C:\test>
C:\test>
My file.txt document contains only one line but the real files are
several hundred thousand lines.
The words I am changing are not just "cow" and "horse" but hundreds of
words.
I am using Windows.
In my commandline program, my question is rather than specifying "s/
cow/fox/g;s/horse/dog/g" on the commandline, I want to reference a
file containing this. In otherwords, I want my commandline program to
reference a text file, lets call it regexReplace.txt, containing the
following
s/cow/fox/g;
s/horse/dog/g;
Can someone help me out with the syntax or how to do this?
Thank you
Dominic