Search email addresses using grep command

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Search email addresses using grep command
# 1  
Old 09-03-2016
Wrench 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:
Code:
iiadam
otterhedgehog
kayleigh
humantvguide@geocities.com
Abicraft
benz@uole.com
303-724-1777
abelsonz
love69
thesecretbang
axluigi@geocities.com
Moschopz
StrangeWizard
garibaldi@uole.com
jewel
ryanatv17
erik
whalecat44
Jordy3000
soctor
v0lc0m172
elnando
itamiken
cattle
jokimjk
harrysbird
janet@uole.com

The question is How many email addresses are in ‘first.last’ name format AND involve someone who’s first name starts with a letter in the first half of the alphabet?


2. Relevant commands, code, scripts, algorithms:

Using grep command only

3. The attempts at a solution (include all code and scripts):

Here's what I tried to search all email addresses, but I don't know to search first.last name and involve someone who’s first name starts with a letter in the first half of the alphabet?

Code:
grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" filename | wc-l

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

School name: UC Boulder, Colorado, United States, David Knox, CSCI-3308


Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
Moderator's Comments:
Mod Comment Please use CODE tags when displaying sample input, sample output, and code segments.

Last edited by Don Cragun; 09-04-2016 at 02:29 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 09-04-2016
Quote:
.... wc -l
As your task is to use grep only, you'll may use a feature of grep instead. Look at the manpage(man grep) again. There should be an option which counts the results.

In general regular expressions can be quiet hard. One possible way to get through a task is to begin simple and after each successful attemp take the next step, like this....

Step 1: Just look at the @:

Code:
 grep '@' list.txt

Step 2: Include the part after the @:

Code:
grep -E -o "@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}"

and so on.

----

Your expression looks quite good. If you assume two-part domains only(...@domain.com not ...@sub.domain.com) the regex is good.

Quote:
but I don't know to search first.last name
You are already using character sets("[...]": a list of wanted characters) and quantifiers("+", or "*" or "{n,m}":how often are they supposed to be there). How would you express firstname with character sets and and quantifiers? The same for lastname? If you have it, just put it together like you did already at an other place within your regex.

Quote:
...who’s first name starts with a letter in the first half of the alphabet?
Dumb question: What characters are exactly in the first half of the alphabet? How would you express that with the construct of a character set "[...]" for the very first character of the firstname? You already used a range(like this: "[A-Z]") in a character set, which will be handy here. Then describe the rest of firstname using another character set.

To create a RegEx pattern, this is a simple procedure, that helps
  1. What char (fixed character, list of possible characters, special character classes) do I want now? -> define the character
  2. How often should it be there? -> write the quantifier(if needed)
  3. Do more characters form a group and this group should be repeated? -> put parenthesis around the group and use the correct quantifier
  4. Move on to the next character
There are too a lot of regex helper sites you can use for interactive testing. Learn by trying: RegExr: Learn, Build, & Test RegEx

Last edited by stomp; 09-04-2016 at 02:15 AM..
# 3  
Old 09-07-2016
Thank you so much.

I think I get it. Appreciate it Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

grep command for email

May I know what is the command-line instruction to show all the subjects and authors of my emails contained in a directory by using egrep? Thanks! (2 Replies)
Discussion started by: marcuslki
2 Replies

2. 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

3. Shell Programming and Scripting

Create email Addresses

Hi, I own 2 websites 1world1game.com and thetoonarmy.net. I can access my 1world accont using mediatemples webmail. The problem i am having is that I want to allow users to register an email from a form on 1World1Game such as tom@thetoonarmy.net and be able to access it from 1world1game. ... (2 Replies)
Discussion started by: rmail2006
2 Replies

4. Shell Programming and Scripting

Email Question - two email addresses

Hello, I have an email script that runs when a process is complete. I would like to have the email sent to two different email addresses, but it is only sending it to the first one. Can you take a look and see what I need to correct? I thought if I surrounded them with double quotes and... (5 Replies)
Discussion started by: jyoung
5 Replies

5. UNIX and Linux Applications

email addresses

Greetings to all. I have installed dadamail on my web site and it works extremely well. I have two questions: 1. I have modified dada to bounce bad emails, but only the first newsletter will use the modifications. If I create another list, it doesn't use the modification. What gives? 2. Are... (0 Replies)
Discussion started by: okbrowder
0 Replies

6. UNIX Desktop Questions & Answers

Using Mailx to send to list of email addresses

Im trying to use a shell script to send to a list of email addresses in a txt file. Here is what i have tried but it keeps sending to dead.letter... Success.ksh contains... mailx -s"Night Batch Success" 'cat /Scripts/email_addresses.txt' < /Scripts/email_body_message.txt The email body... (1 Reply)
Discussion started by: aguad3
1 Replies

7. Forum Support Area for Unregistered Users & Account Problems

keeps telling me my email addresses don't match

HI there, Trying to register but it keeps telling me my email address doesn't match. I tried several times. I even tried closing out and coming back to the page. Thanks (0 Replies)
Discussion started by: r0k3t
0 Replies

8. UNIX for Dummies Questions & Answers

How to delete old email addresses?

Help! Need to delete old email addresses from address book on Dell Windows 98............. -------- The subject line was one long string - I inserted spaces - oombera (1 Reply)
Discussion started by: Deede
1 Replies

9. Programming

How to delete email addresses

I need to delete old email addresses and can't them them out of my address I have a dell and am served by MSN? (Email address removed... Neo) (4 Replies)
Discussion started by: Deede
4 Replies
Login or Register to Ask a Question