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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting New to Perl Mail @ sign search and replace in a file
# 1  
Old 08-03-2012
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
Code:
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 users changes their email addresses often , sometime I have to add an email adress in the middle of these or end of line ..

sample of entries in my file .. all email addressss are sepearted by comma
over 100 emails in it

joe.1@uuu.com,joe.2@uuu.net


If I use %s/old/new/ in VI session I can replace an entry

first problem:

When I use this perl command it fails .. I have no idea how to esape the
@ sign

Code:
perl -p -i -e  's/old@uuu.net/new@uuu.com' filename


Can someone help me with this?

I'm using Linux Environment
Moderator's Comments:
Mod Comment Code tags for code, please.

Last edited by Corona688; 08-03-2012 at 11:49 AM..
# 2  
Old 08-03-2012
It looks like you forgot the ending / on that expression. 's/old@uuu.net/new@uuu.com/
# 3  
Old 08-03-2012
Hey Corona688

I just missed it on this forum .. Adding it does not help on the command like. I need to be able to escape the @ character ? Can u help?
# 4  
Old 08-03-2012
Try a backslash, like \@.
# 5  
Old 08-03-2012
Code:
$ echo "test@test.com" | perl -pe 's/test\@test.com/abc\@abc.com/'
abc@abc.com

This User Gave Thanks to itkamaraj For This Post:
# 6  
Old 08-03-2012
Thanks !!! itkamaraj -- It worksSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl- read search and replace string from the file

Dear all, I have a number of files and each file has two sections separated by a blank line. At the top section, I have lines which describes the values of the alphabetical characters, # s #; 0.123 # p #; 12.3 # d #; -2.33 # f #; 5.68 <blank line> sssssss spfdffff sdfffffff Now I... (4 Replies)
Discussion started by: sasharma
4 Replies

2. Shell Programming and Scripting

How to search/replace a directory path in a file using perl

Hello All, Here is what I am trying to do and maybe you guys can point me in the right direction. I have a file that contains the following string(s): WARNING: </d1/test/program1> did not find item1 WARNING: </d1/test/program1> item1 does not exist WARNING: </d1/test/program2> item1 failed... (1 Reply)
Discussion started by: maxshop
1 Replies

3. Shell Programming and Scripting

Search and Replace in Perl

I am trying to write a simple perl script to run on a FreeBSD machine. There are alot of posts here, and I have read so many, yet can not get this script to run. #!/usr/bin/perl -e 's/\r\n/~/' infile.txt outfile.txt I am trying to take a windows text file, move it into Unix, run a script on... (1 Reply)
Discussion started by: mach1
1 Replies

4. Shell Programming and Scripting

Interesting question - Search and replace the word after sign "="

Hi Guys, Req your help in searching and replacing the word that comes after equals(=) symbol I would like to replace the sting in bold with a string in variable. d=ABCDF8C44C22 # grep -i NIM_MASTERID ${_NIMINFO} export NIM_MASTERID=00CDF8C44C00 I'm looking to replace any word that... (4 Replies)
Discussion started by: ajilesh
4 Replies

5. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: cacm1975
2 Replies

6. Shell Programming and Scripting

How to search a date format from a file an replace with a string in PERL

I am very new to Perl. I am struggling so hard to search a date (such as 10/09/2009, 10-09-2009) from a text file and replace with a string (say DATE) using Perl. Please help me out. Thanks in advance. Regds Doren (4 Replies)
Discussion started by: my_Perl
4 Replies

7. Shell Programming and Scripting

Perl search and replace file content.

I am not sure if this is doable. I am trying to open and print the content of the file by replacing all instances fo perl to PERL . This is my code but it is giving me the number count instead of the actual lines with changes. open (PERLHISTORY, 'sample.txt') or die "The file sample.txt could... (3 Replies)
Discussion started by: jxh461
3 Replies

8. Shell Programming and Scripting

Search and replace in Perl

Hello, I have a Perl script that reads in an Excel spread sheet and formats the values into a text file. I am having trouble with one column that can have numbers or letters. Excel left justifies the values that start with a letter and right justifies the values that contain only a... (2 Replies)
Discussion started by: jyoung
2 Replies

9. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

10. HP-UX

Replace $ sign within a file using Vi editor

Can someone help me with this command? I want to replace amount fields which are in the format $99.99 to 99.99 in a large data file which is within a HP box. I use Vi editor and tried this command :1,$s//$///g And this does not seem to work Also, I want to replace ^M with spaces in the... (1 Reply)
Discussion started by: dtonse
1 Replies
Login or Register to Ask a Question