LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Matching a domain with grep (https://www.linuxquestions.org/questions/programming-9/matching-a-domain-with-grep-681427/)

abefroman 11-05-2008 10:47 PM

Matching a domain with grep
 
Hi,

I need help matching a domain with grep.

I have
mydomains.txt
which contains
DNS1=mydomain.com
DNS2=mydomain.net
DNS3=mydomain.org
DNS4=sub.mydomain.com

and when I run
cat mydomains.txt |grep expression
I want it to match the top level domains only (not the subdomains)

What would the correct expression for this be?

I tried:
cat mydomains.txt |grep ^DNS[1-9]=[a-z]\.
but that matches the subdomain too

and I tried:
cat mydomains.txt |grep ^DNS[1-9]=[a-z]\.[com|net|org]
which doesnt match any

and
cat mydomains.txt |grep ^DNS[1-9]=[a-z]\.[a-z]*
which matches all

and
|grep ^DNS[1-9]=[a-z]\.[a-z^\.]*
which matches all

and
|grep ^DNS[1-9]=[a-z]\.[a-z^\.]+
which matches none

How can I get it to match all but the subdomain?

TIA!

burschik 11-06-2008 01:17 AM

Quote:

Originally Posted by abefroman, the Support King of Chicago (Post 3333061)
Hi,
I want it to match the top level domains only (not the subdomains)

What would the correct expression for this be?

Code:

grep "^DNS[1-9]=[a-z]\+\.[a-z]\+$" mydomains.txt

abefroman 11-06-2008 03:07 AM

Thanks that worked.


All times are GMT -5. The time now is 04:36 AM.