LinuxQuestions.org
Review your favorite Linux distribution.
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
  Search this Thread
Old 11-05-2008, 10:47 PM   #1
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Rep: Reputation: 55
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!
 
Old 11-06-2008, 01:17 AM   #2
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
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
 
Old 11-06-2008, 03:07 AM   #3
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

Original Poster
Rep: Reputation: 55
Thanks that worked.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
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
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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:25 PM.

Main Menu
Advertisement
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
Twitter: @linuxquestions
Open Source Consulting | Domain Registration