remove the text (*@yahoo.com, hotmail.com) from one file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting remove the text (*@yahoo.com, hotmail.com) from one file
# 8  
Old 06-15-2008
Quote:
Originally Posted by radoulov
I think you mean GNU Awk.
Yes I meant gawk. gensub() is only available in gawk.

Your perl solution produces this on my sample file:
Code:
abc@test.com: 
xyz@test.com: 
qwer@test.com: qwer@test2.com
ghjk@test.com: ghjk@test2.com
abcd@xyz.com: abcd@hjkl.combcd@mil.com

What about:
Code:
perl -pe's/(,\s?)?\w+@(?:(?:hot|g)mail|aol|yahoo)\.com,?/\1/g' input-file

# 9  
Old 06-15-2008
Quote:
Originally Posted by ripat
[...]Your perl solution produces this on my sample file:
Code:
abc@test.com: 
xyz@test.com: 
qwer@test.com: qwer@test2.com
ghjk@test.com: ghjk@test2.com
abcd@xyz.com: abcd@hjkl.combcd@mil.com

What about:
Code:
perl -pe's/(,\s?)?\w+@(?:(?:hot|g)mail|aol|yahoo)\.com,?/\1/g' input-file

Yep,
good point.
But:

Code:
zsh-4.3.4% perl -pe's/(,\s?)?\w+@(?:(?:hot|g)mail|aol|yahoo)\.com,?/\1/g'<<<'abcd@fghj.com
,abcd@hotmail.com'
abcd@fghj.com,

If I'm not missing something again:

Code:
s/\w+@(?:(?:hot|g)mail|aol|yahoo)\.com,?//g;s/,$//

It won't handle this of course:

Code:
email@yahoo.com ,

So, may be:

Code:
s/\w+@(?:(?:hot|g)mail|aol|yahoo)\.com(?:\s?,)?//g;s/,$//


Last edited by radoulov; 06-15-2008 at 06:08 AM..
# 10  
Old 06-15-2008
Quote:
Originally Posted by matrixmadhan
Code:
tr ' ' '\n' < a | while read line
do
echo "$line" | egrep -v "hotmail|yahoo" 2>/dev/null 1>&2
if [ $? -eq 0 ]
then
echo "$line"
fi
done

isn't this the same as
Code:
tr ' ' '\n' < a | egrep -v "hotmail|yahoo" 2>/dev/null 1>&2
...

without the extra while loop.
# 11  
Old 06-15-2008
Quote:
Originally Posted by ghostdog74
isn't this the same as
Code:
tr ' ' '\n' < a | egrep -v "hotmail|yahoo" 2>/dev/null 1>&2
...

without the extra while loop.
... and why redirecting the standard error?
# 12  
Old 06-15-2008
Quote:
Originally Posted by radoulov
... and why redirecting the standard error?
nah...just cut and pasted...forgot to remove them. its not needed.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove the text between all curly brackets from text file?

Hello experts, I have a text file with lot of curly brackets (both opening { & closing } ). I need to delete them alongwith the text between opening & closing brackets' pair. For ex: Input:- 59. Rh1 Qe4 {(Qf5-e4 Qd8-g8+ Kg6-f5 Qg8-h7+ Kf5-e5 Qh7-e7+ Ke5-f5 Qe7-d7+ Qe4-e6 Qd7-h7+ Qe6-g6... (6 Replies)
Discussion started by: prvnrk
6 Replies

2. Shell Programming and Scripting

Cut text from a file and remove

Hello Friends, I am stuck with the below problem.Any help will be appreciated. I have a file which has say 100 lines. On the second last line I have a line from which i want to remove certain characters.. e.g CAST(CAST( A as varchar(50)) || ',' || CAST(CAST( B as varchar(50)) || ',' ||... (8 Replies)
Discussion started by: vital_parsley
8 Replies

3. Shell Programming and Scripting

Search and remove in a text file

Need help whit a script where I have to input a name and then remove a line where that name is in a file file ex: 001op;Name;Location;date 002op;Name;Location;date and so on.... can anybody help me??? thanks (4 Replies)
Discussion started by: nogame11
4 Replies

4. Shell Programming and Scripting

Remove filename is text file

Hello, I got files full path in a text file like that /main/k/kdelibs/kdelibs4c2a_3.5.10.dfsg.1-2ubuntu7_i386.deb /main/k/kdelibs-experimental/libknotificationitem-dev_4.3.2-0ubuntu1_i386.deb /main/k/kdemultimedia/dragonplayer_4.3.2-0ubuntu1_i386.deb... (13 Replies)
Discussion started by: davidkhan
13 Replies

5. Shell Programming and Scripting

remove chunks of text from file

All, So, I have an ldif file that contains about 6500 users worth of data. Some users have a block of text I'd like to remove, while some don't. Example (block of text in question is the block starting with "authAuthority: ;Kerberosv5"): User with text block: # username, users,... (7 Replies)
Discussion started by: staze
7 Replies

6. Shell Programming and Scripting

able to remove \240 from a text file

I have a file originally provided from a SQL database on a Windows platform. I transfer the file via ftp in binary format, remove the ^M's from the end of all lines. I have attempted to use tr ( cat infile | tr -d '\240' ) and sed (cat infile | sed 's/\240//g' ) to remove the occurences of... (11 Replies)
Discussion started by: pbrowne
11 Replies

7. Shell Programming and Scripting

remove and replace text in a file

Hello all, How would I go to a particular line in a file and remove certain text from it and replace with something that I want it to be there. like: file /etc/abc now look for line HOME="/export/xyz" in /etc/abc and then replace with HOME=/"export/xyz1" thanks in advance guys. (1 Reply)
Discussion started by: solaix14
1 Replies

8. Shell Programming and Scripting

remove specified text from file

I am trying to write a script that kills old sessions, I've posted here over the past few days and the script is just about perfect except I want to be given the option to exclude specified PIDs from being killed. this is the entire script: if then rm /tmp/idlepids fi if then rm... (2 Replies)
Discussion started by: raidzero
2 Replies

9. UNIX for Dummies Questions & Answers

Send mail to any user (@hotmail,@yahoo etc) from Solaris

Hi All, I am new to unix. I want to know what are the steps to do in order to configure a unix server (Solaris 8) to send mails to the outside world. I also want to send attachments in the mail. Thanks in advance Zing (2 Replies)
Discussion started by: zing
2 Replies
Login or Register to Ask a Question