Re: one liner for replacing under Windows?
[email protected] ("Xavier Noria")
| Newsgroups | perl.beginners |
|---|---|
| Message-ID | <[email protected]> |
On Sat, Jun 14, 2008 at 1:05 PM, Octavian Rasnita <[email protected]> wrote: > From: "Xavier Noria" <[email protected]>> On Sat, Jun 14, 2008 at 9:56 AM, > Octavian Rasnita <[email protected]> wrote: >> >>> Is there a one-liner command that can replace a certain text with another >>> in >>> more files specified with wildcards like *.html that works under Windows >>> cmd? >> >> Since you ask this you probably know the Windows shell does not expand >> wildcards. There's a trick for Perl one-liners though (untested): >> >> perl -e "@ARGV = glob(qq($ARGV[0])); s/foo/bar/ while <>" >> >> You see the idea. >> > > Thank you but I don't think it works without writing a full perl program in > a single line that does that. > > If I just replace the string in $_, the files are not updated. > > If I also use -pi.bak parameter in order to do that, it gives an error > telling that the specified file (*.txt) can't be opened. > > So I can't see another solution than opening the files, making the > replacement than writing the new content. Absolutely, try putting a BEGIN block around (again untested): perl -pi.bak -e "BEGIN { @ARGV = glob(shift) } s/foo/bar/g" "*.html" -- fxn