Unix/Linux Go Back    


Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

Search email addresses using grep command

Homework & Coursework Questions


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-03-2016   -   Original Discussion by ForeignGuy
ForeignGuy ForeignGuy is offline
Registered User
 
Join Date: Sep 2016
Last Activity: 7 September 2016, 12:23 AM EDT
Location: Colorado
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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:
Search email addresses using grep command 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.
Sponsored Links
    #2  
Old Unix and Linux 09-04-2016   -   Original Discussion by ForeignGuy
stomp stomp is online now
Registered User
 
Join Date: May 2016
Last Activity: 20 November 2017, 8:12 AM EST
Posts: 193
Thanks: 10
Thanked 67 Times in 62 Posts
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..
Sponsored Links
    #3  
Old Unix and Linux 09-07-2016   -   Original Discussion by ForeignGuy
ForeignGuy ForeignGuy is offline
Registered User
 
Join Date: Sep 2016
Last Activity: 7 September 2016, 12:23 AM EDT
Location: Colorado
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you so much.

I think I get it. Appreciate it Linux
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Formatting list of IP addresses into a grep command lewk Shell Programming and Scripting 7 02-08-2012 06:14 AM
Create email Addresses rmail2006 Shell Programming and Scripting 2 08-27-2009 06:34 AM
Email Question - two email addresses jyoung Shell Programming and Scripting 5 08-04-2008 02:00 PM
email addresses okbrowder UNIX and Linux Applications 0 04-20-2008 04:02 PM
How to delete email addresses Deede Programming 4 02-02-2004 07:23 PM



All times are GMT -4. The time now is 09:17 AM.