Perl how to replace e-mail address from the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl how to replace e-mail address from the file
# 1  
Old 11-16-2009
Perl how to replace e-mail address from the file

I have a script which updates the users e-mail address according to wherever the users type in the browser. The script does other stuffs but this what i am struggling with ..lol. Basically, we are using the command below to try to update the e-mail, however since the e-mail address has "@" the perl is not able to update (e-mail is not an array).

perl -pe 's/$old_email/$newemail/g' -pi $file`;

The e-mail are defined in two variables (old and new email)

Can you anyone please help me on this?

ps: Sorry, i am new using perl.Smilie

Thank you all,
Carlos
# 2  
Old 11-16-2009
You have to quote @'s.

pail\@somewhere.com

You don't show where $old_mail and $newmail come from. If they have been se at the command line, that's the problem. It wouldn't be a problem if you read them from a file.
# 3  
Old 11-17-2009
Hi Tony, thanks for your reply.
Actually the values are typed by the users (from the a webpage) and then the they are stored in the variable ->$newemail and $old_mail and it is in the file.

In the code it is more like this:

for ($i=0, $i<$sw, $i++)
{
local $tmp_email ="FORM_EMAIL$j";
$newemail ="$ENV{$tmp_email}";

`perl -pe 's/$old_email[$j]/$newloc $newemail/g' -pi $file`;

}

$sw -> it the users number

So, I am not sure this can be done as you said "pail\@somewhere.com", since the values are encrypted into the variables.

Thanks for your help.
Carlos

---------- Post updated 11-17-09 at 01:05 AM ---------- Previous update was 11-16-09 at 04:59 PM ----------

Please help meSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

How to replace Ip address in .xml file through shell script?

I have one .xml file. which contains the following line. <ParamString StringId="PortAddress" StringValue="172.27.166.170" /> <ParamString StringId="PortAddress" StringValue="172.27.166.171" /> <ParamString StringId="PortAddress" StringValue="172.27.166.202" /> <ParamString... (9 Replies)
Discussion started by: Anjan Ganguly
9 Replies

2. Red Hat

How to send mail with sender mail address and name?

Hi, I am trying to send a mail using "mail" command in unix. I wanted to give sender name and sender address. I tried different options ,but still it shows only mail address(No name). mail -s "Alert mail : Nothing running !!!" $email -- -F"Mail Alert" -fno-reply@alert.com But I am getting... (4 Replies)
Discussion started by: jaggy
4 Replies

3. Shell Programming and Scripting

HELP simple script to find e-mail address on a file

Hello guys, im new to to unix/linux i have a text file like this: person1@test.com iisiiasasas person2@test.com 123w2 3233 sajsja person3@test.com jsajjsa sajsjasaj person4@test.com I want to extract only e-mail address and get rid of all other stuff, i want an output like this ... (4 Replies)
Discussion started by: RazorMX
4 Replies

4. Shell Programming and Scripting

New to Perl Mail @ sign search and replace in a file

HI I'm terribly new to perl .. I;ve been trying to use this command to search and replace entries in a file I tried this and it works perl -p -i -e 's/old/new/' filename Problem is that I have a list of email addresses and I need to serach and replace the entire email address as my... (5 Replies)
Discussion started by: mnassiri
5 Replies

5. Shell Programming and Scripting

mail using mail address in a file

I have a file which contains few email address. I have few scripts which use the same mail address. so if any change in mail id like if any user do not want to receive the mail i can just edit a single file instead of many scripts. So i want the scripts to use that file. How can this be done. (2 Replies)
Discussion started by: gpk_newbie
2 Replies

6. Shell Programming and Scripting

How to replace a value in a file in perl?

Hi, I have a file with the following contents and i want to replace that value in a file with some other value. #file.txt /local/Disk/data n 192.168.55.98 52035 3 1 2 1 1 192.168.55.98 Here is my code. (2 Replies)
Discussion started by: vanitham
2 Replies

7. Shell Programming and Scripting

mailx -s not sending the file to mail address

Hi All, OS:Red Hat Linux 4 86x64 Below is my shell script which is not sending mail to the mail recipient: #!/bin/bash export MAILLIST="xyz@yahoo.com" cd <path_to_the_script_perf_report.sql> sqlplus / as sysdba @perf_report.sql if then cat <path_to_the_script/*MONTHLY*REPORT*.lst... (6 Replies)
Discussion started by: a1_win
6 Replies

8. Shell Programming and Scripting

Mail the contents of a file in perl

Hi, I'm trying to read the contents of a file (message.txt), put them in a mail and then mail it This is what I have thus far but I having trouble referencing the file. I'm trying to put it into an array so any ideas would be helpful ... $to='user.n@domain.com'; $from= 'username';... (7 Replies)
Discussion started by: cillmor
7 Replies

9. UNIX for Dummies Questions & Answers

send mail file from server to another address

HP-UX B11.23 ia64 I have a users mail inbox in /var/mail I want to send all the mail there to another address (an Exchange address). At the Exchange address, I want it to appear as the original separate emails, with attachments in their original form (e.g. still MIME encoded). Is that... (6 Replies)
Discussion started by: LisaS
6 Replies

10. Shell Programming and Scripting

Pull E-mail address from file, send e-mail

Hello, I am new to perl and need to create a script that will read a file and pull a name from the file and send e-mail. How can I use the following awk statement in a perl script? grep UNIXadmins /root/mail.conf | awk '{ print $2}' and use the output to send a e-mail. Any help would... (1 Reply)
Discussion started by: DC Heard
1 Replies
Login or Register to Ask a Question