in reply to Re: Word Replacing
in thread Word Replacing

Hi, thankx for the help, BUT nothin of this is working ...

I tryed all the examples which were mentioned here ...
perl -pi.orig -e 's/original/substitute/g' <filename>


or
perl -spi -e 's/Bartholome/Richard/g' /path/to/folder/*


The only thing what i achieved was, that my command line told me that i cant work with a file without and backoup or something like that ...

Than even the full script, but it was full of errors, about 2-3 ...

Guys, i know that i am like an insect but i really need help ... And you are my only hope - or i have to spend hours replacing a word by hand ... Please write me an exact way how to do that ...

Than, if youll be in Slowakia lemme know, ill buy you a beer ... Thank you

Replies are listed 'Best First'.
Re^3: Word Replacing
by xoddam (Novice) on Jun 04, 2007 at 22:29 UTC
    perl -p -i_ARCHIVE.txt -e "s/original/subst/g" <path to FILE>


    good, afrer HOURS spend on googling the net i found this one ... Its workning on MS WIN without problems ...

    It replaces the word, saves it under original form {name and file type} and creates a backup in form : original_ARCHIVE.txt ...

    Nice ... And now the last thing what i need is, how to work with more files? If i type in as path to file:

    C:/test/* - Does not work C:/test/*.* - Does not work C:/test/"*" - Does not work C:/test/"*.*" - Does not work


    And so i have NO idea hot to let him work with all files in a folder, what you told me does not work ..

      You may have to forgo the single-line command, and do something akin to this (which is not tested)

      use strict; use warnings; my $newfolder = shift(@ARGV); use Tie::File; use Fcntl 'O_RDWR'; chdir($newfolder); my @list=glob("*"); foreach my $file (@list){ tie @array, 'Tie::File', $file, mode => O_RDWR or die "could not tie $ +file because...$!\n" foreach my $record (@array) { $record =~ s/$oldword/$newword/ig; } }

      Read docs on Tie::File; it will probably help.

      Also, read up on glob.

      emc

      Any New York City or Connecticut area jobs? I'm currently unemployed.

      There are some enterprises in which a careful disorderliness is the true method.

      —Herman Melville