Sifting out mail addresses with grep and regex


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Sifting out mail addresses with grep and regex
# 1  
Old 10-01-2019
Sifting out mail addresses with grep and regex

Hi there from a newbie.

So, I have this huuuge portion of mail addresses with names interlaced.. looks like:
Code:
"name1" <mail1@domain1.com>, "name2" <mail2@domain2.com> ... 

Sometimes there are no names, just mailaddress. My thought was to use regex with grep. I saved the list in file ma and tried the command
Code:
cat ma | grep -ioE \<[.*]\>

then I got no output. I fiddled around a little and gave the command
Code:
cat ma | grep -ioE \<*.\>

which resulted in a lot of "e> e> m> e> m>m>" each on a new line. So what I see here is the last character of the mail address along with the >. Not far from the wanted result but still not correct. The command doesn't make any sense to me. I'm completely puzzled! Where am I going wrong???

Please help me!
/Lasse

Last edited by RavinderSingh13; 10-01-2019 at 09:07 AM..
# 2  
Old 10-01-2019
Hello dr_xemacs,

Could you please try following once.

Code:
awk '{while(match($0,/<[^>]*>/)){print substr($0,RSTART+1,RLENGTH-2);$0=substr($0,RSTART+RLENGTH)}}'  Input_file

Thanks,
R. Singh
# 3  
Old 10-01-2019
Mayhap sth. like
Code:
echo "name1 <mail1@domain1.com>, name2 <mail2@domain2.com>  " | grep -ioE "<[^>]*>"
<mail1@domain1.com>
<mail2@domain2.com>

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep for all ip addresses mentioned in all files in a Directory

I wish to traverse all files and folders under a given directory say "/tmp/configuration" and for all ip address mentioned therein. I tried find ./ -type f | xargs grep "*.*.*.*" but it does not populated the correct results. Can you please suggest. (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Homework & Coursework Questions

Search email addresses using grep command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Let's say if we have a file with a lot of information. For example: iiadam otterhedgehog kayleigh... (2 Replies)
Discussion started by: ForeignGuy
2 Replies

3. Shell Programming and Scripting

Extract e-mail addresses on a page

Hi I normally ask questions on coding but I think there is a code that can do this. I have regular text throughout my file and I want to extract all e-mail addresses from it (rather than going and searching each one). E-mails all have @ so I assume there is a way. Thanks Phil (6 Replies)
Discussion started by: phil_heath
6 Replies

4. Shell Programming and Scripting

Formatting list of IP addresses into a grep command

Hi I have an input file with a list of random IP addresses, each on a new line. Below is just an example as I omitted the real IP addresses for obvious reasons. Input: random_ip.txt 10.0.0.1 10.0.0.1 10.0.0.1 10.0.0.1 10.0.0.1 10.0.0.1 10.0.0.1 10.0.0.1 10.0.0.1 10.0.0.1... (7 Replies)
Discussion started by: lewk
7 Replies

5. Shell Programming and Scripting

Perl - match e-mail addresses in multiple files

Hi, I'm trying to write a script that will check multiple files in a directory (all the relevant filenames begin "TT04.NOTES") for e-mail addresses, and then print these addresses to screen with a count at the bottom. I'm a bit of a novice with Perl but thought it would be the best tool for the... (2 Replies)
Discussion started by: wf1974
2 Replies

6. Shell Programming and Scripting

Echo - Sending mail to multiple addresses

Hi, If I want my script to send a mail to multiple recipients I can do the following: if then echo $err_string1 | mailx -s "UAT CPU ALERT" 1@email.com echo $err_string1 | mailx -s "UAT CPU ALERT" 2@email.com fi Can this also be done something like: ... (1 Reply)
Discussion started by: runnerpaul
1 Replies

7. UNIX for Dummies Questions & Answers

| help | unix | grep (GNU grep) 2.5.1 | advanced regex syntax

Hello, I'm working on unix with grep (GNU grep) 2.5.1. I'm going through some of the newer regex syntax using Regular Expression Reference - Advanced Syntax a guide. ls -aLl /bin | grep "\(x\)" Which works, just highlights 'x' where ever, when ever. I'm trying to to get (?:) to work but... (4 Replies)
Discussion started by: MykC
4 Replies

8. Shell Programming and Scripting

How can i send mail to multiple addresses in same domain in bash?

Suppose i have a txt file that is the list of the addresses,something like: lala0045 john james lala0234 george james and i want to send an email to lala0045@blabla.com and lala0234@blabla.com,the same domain...what is the exact syntax i should use in my script? there is a command... (10 Replies)
Discussion started by: bashuser2
10 Replies

9. UNIX for Dummies Questions & Answers

unix-mail to external websites/addresses

Hi all, I would like to know if I can send unix mail to 'external email addresses'. My unix server is leo@ABCcompany.com. I am able to send emails to firstname.lastname@ABCcompany.com. But, we have some email addresses in our team on our parent company's server - ex:... (2 Replies)
Discussion started by: Joy_K
2 Replies
Login or Register to Ask a Question