Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I see your help. My company changed the name from xyz corp to xyzabc corp. Now I need to change the emails on the entire website. For each instance of @xyz.com @xyzabc.com possibly in the email address. How do I do this with Perl?

Replies are listed 'Best First'.
Re: Namechange
by allolex (Curate) on Nov 28, 2003 at 16:33 UTC

    In the spirit of giving a man a fish, go ahead and try this one-liner on each of the files you need changed:

    perl -i.bak -pe's=\@xyz\.com=\@xyzabc.com=g;'

    This can be done very easily in Perl, but this one-liner will not help you if the text you are trying to replace spans two lines. (The -i.bak bit makes a backup of the files you change, but be careful, anyway.)

    --
    Allolex

    Update: Shamelessly escaped the @s according to diotalevi's and nvuku's good advice. I seem to be having a sloppy night. /me goes off to look for mistakes in other nodes.

Re: Namechange
by Joost (Canon) on Nov 28, 2003 at 16:22 UTC
    Take a look at this info:

    You probably want something like
    perl -i.orig -p -e 's/@xyz\.com/@xyzabc.com/g'

    Joost

    -- #!/usr/bin/perl -w use strict;$;= ";Jtunsitr pa;ngo;t1h\$e;r. )p.e(r;ls ;h;a;c.k^e;rs ";$_=$;;do{$..=chop}while(chop);$_=$;;eval$.;

      @xyz is interpolated. Escape the @.

      perl -i.orig -p -e 's/\@xyz\.com/\@xyzabc.com/g'
Re: Namechange
by PrimeLord (Pilgrim) on Nov 28, 2003 at 16:26 UTC
    This can be done with a one liner, but to give you an idea how this works you can move the web page to a back up, read it in line by line and just substitute the old address with the new address. For this example I will assume your html fuile is called index.html.

    ** Warning Unested Code **

    open OUT, "> index.html" or die "$!"; # open the new HTML file open IN, "index.html.old" or die "$!"; open the old HTML file to be re +ad in while (<IN>) { s/@xyz\.com/@xyzabc\.com/g; #for every line that has @xyz.com r +eplace it with @xyzabc.com print OUT; # print the line into the new HTML file } close IN or warn "$!"; # close the old file close OUT or warn "$!"; # close the new file


    That should do it.

    - Prime