Combining grep patterns with OR condition?!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Combining grep patterns with OR condition?!
# 1  
Old 12-08-2014
Error Combining grep patterns with OR condition?!

Hello!

I have a question about how to combine patterns in grep commands with the OR operator.

So I have this little assignment here:

Provide a regular expression that matches email addresses for San Jose City College faculty. A San Jose City college faculty’s email address takes the form:
<only first letter of first name><last name>@sanjosecity.edu or
<only first letter of first name><last name>@sjcc.edu
The letters for first name and last name are all lower case letters. Last name must contain at least one (or more) letter. Examples: bloo@sanjosecity.edu or bloo@sjcc.edu


So I came up with two separate grep commands:

Code:
grep '^[a-z]\{2,\}\@sjcc\.edu$' file.txt

and

Code:
grep '^[a-z]\{2,\}\@sanjosecity\.edu$' file.txt

But I have no idea how to combine them together!! I tried using the OR operator, the | , but it would not give me the correct result. It would ignore the "sanjosecity" pattern, and just satisfy the "sjcc" one.

How do I combine the patterns successfully, while still making sure that either way, the email is all lower case letters? (NO NUMBERS!)

Any help would be greatly appreciated!!
I'm preparing for my final tomorrow and I'm getting nervous because I can't seem to solve this Smilie
# 2  
Old 12-08-2014
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep patterns

Hi Experts, I have a log file like this.I need to filter the Index name and elapsed time(only created ). 06:36:39 SQL> create index XYZ_F75 on XYZ 06:36:39 2 ("GRP_ID", "_ID") parallel 64 nologging 06:36:39 3 tablespace XARGS_IDX 06:36:39 4 ; Index created. Elapsed:... (2 Replies)
Discussion started by: navsan420
2 Replies

2. UNIX Desktop Questions & Answers

Combining files with specific patterns of naming in a directory

Greetings Unix exports, I am facing some problems in combining files with different name patterns with a directory and I would appreciate if you can help me I have more than 1000 files but they follow a specific pattern of naming. e.g. 64Xtest01.txt They are divided into two sets of test and... (9 Replies)
Discussion started by: A-V
9 Replies

3. Shell Programming and Scripting

Combining find, grep and possibly ls?!

Hi - can someone please help me combine find, grep and possibly ls into something workable: i.e. How can I list all the files that contain the word "pet" in all directories under the current directory that are called "animal", bar those anywhere under directories called "archive"? I suspect... (6 Replies)
Discussion started by: cs03dmj
6 Replies

4. Shell Programming and Scripting

matching patterns inside a condition in awk

I have the following in an awk script. I want to do them on condition that: fext == "xt" FNR == NR { />/ && idx = ++i $2 || val = $1 next } FNR in idx { v = val] } { !/>/ && srdist = abs($1 - v) } />/ || NF == 2 && srdist < dsrmx {... (1 Reply)
Discussion started by: kristinu
1 Replies

5. Shell Programming and Scripting

Combining multiple rows in single row based on certain condition using awk or sed

Hi, I'm using AIX(ksh shell). > cat temp.txt "a","b",0 "c",bc",0 "a1","b1",0 "cc","cb",1 "cc","b2",1 "bb","bc",2 I want the output as: "a","b","c","bc","a1","b1" "cc","cb","cc","b2" "bb","bc" I want to combine multiple lines into single line where third column is same. Is... (1 Reply)
Discussion started by: samuelray
1 Replies

6. UNIX for Dummies Questions & Answers

Grep - various patterns

I have a file with the following text: grep \$ grep \\$ grep \\\$ grep '\$' grep '\'$' grep \\ grep \\\\ grep "\$" grep '"$' grep "$" When I perform these same commands on this file, the result are never what I would expect them to be. Could someone please comment on the results and... (3 Replies)
Discussion started by: uran101
3 Replies

7. Shell Programming and Scripting

grep value between two patterns

Hi All, I've been trying solve this with a simple command but not having much luck. I have a file like this: Line 1: random_description 123/alert/high random_description2 356/alert/slow Line 2: random_description3 654/alert/medium Line 3: random_description4 234/alert/critical I'm... (7 Replies)
Discussion started by: joe19
7 Replies

8. UNIX for Dummies Questions & Answers

Combining find, grep and gzip

I'm trying to see which files have a particular word in them. The files are all text files but are gzipped and are in sub directories. In order to view the content of a single gzipped file I tried: cat filename | gzip -d | less , and it shows the files contents. But, I want to see a list... (1 Reply)
Discussion started by: thoughts
1 Replies

9. Shell Programming and Scripting

Grep for Multiple patterns

Hi All, I have a file. I need to find multiple patterns in a row and need those rows to divert to new file. I tried using grep -e / -E / -F options as given in man. But its not working. ==> cat testgrep.txt william,fernandes,xxxxx mark,morsov,yyyy yy=,xx= yyyy=,xxxx== ==>... (7 Replies)
Discussion started by: WillImm123
7 Replies

10. Shell Programming and Scripting

Grep multiple patterns

Hi, Can we grep multiple patterns in UNIX. for example: cat /x/y/oratab | grep -i "pattern1|pattern2" .... etc I require the syntax for multiple patterns. | is not working as I explained in example. Malay (4 Replies)
Discussion started by: malaymaru
4 Replies
Login or Register to Ask a Question