LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Thread Tools
Old 11-05-2008, 10:47 PM   #1
abefroman
Member
 
Registered: Feb 2004
Distribution: CentOS w/Cpanel
Posts: 692
Thanked: 0
Matching a domain with grep


[Log in to get rid of this advertisement]
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!
abefroman is offline     Reply With Quote
Old 11-06-2008, 01:17 AM   #2
burschik
Member
 
Registered: Jul 2008
Posts: 158
Thanked: 0
Quote:
Originally Posted by abefroman, the Support King of Chicago View Post
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
burschik is offline     Reply With Quote
Old 11-06-2008, 03:07 AM   #3
abefroman
Member
 
Registered: Feb 2004
Distribution: CentOS w/Cpanel
Posts: 692
Thanked: 0

Original Poster
Thanks that worked.
abefroman is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use grep to print just the matching expression and nothing else new_2_unix Linux - Newbie 5 01-07-2008 05:02 PM
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 7 01-06-2008 02:10 AM
Problem with grep matching to end of line icedown Linux - Newbie 12 09-23-2007 05:43 AM
pattern matching question - grep cbriscoejr Programming 1 02-09-2006 08:30 PM
Problem matching strings with grep/egrep Seb74 Linux - Newbie 5 05-26-2005 01:40 PM


All times are GMT -5. The time now is 02:22 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration