From owner-freebsd-questions Thu May 11 12:56:25 2000 Delivered-To: freebsd-questions@freebsd.org Received: from houston.matchlogic.com (houston.matchlogic.com [205.216.147.127]) by hub.freebsd.org (Postfix) with ESMTP id 90C7D37BB6A for ; Thu, 11 May 2000 12:56:22 -0700 (PDT) (envelope-from crandall@matchlogic.com) Received: by houston.matchlogic.com with Internet Mail Service (5.5.2650.21) id ; Thu, 11 May 2000 13:56:13 -0600 Message-ID: <5FE9B713CCCDD311A03400508B8B3013B256B8@bdr-xcln.is.matchlogic.com> From: Charles Randall To: Mitch Collinsworth , Dan Larsson Cc: questions@FreeBSD.ORG Subject: RE: regexp driving me nuts, help needed! Date: Thu, 11 May 2000 13:56:10 -0600 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain; charset="iso-8859-1" Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG That seems like a lot of work, % echo http://www.domain.com/www.blah/html.asp | perl -ne 'print $1,"\n" if m|http://www\.([^/]+)|i' domain.com This will work with a big list of URLs on stdin. Charles -----Original Message----- From: Mitch Collinsworth [mailto:mkc@Graphics.Cornell.EDU] Sent: Thursday, May 11, 2000 11:27 AM To: Dan Larsson Cc: questions@FreeBSD.ORG Subject: Re: regexp driving me nuts, help needed! >I need to get the domain and tld from an url. > >this my idea of what would match and return 'domain.com': >echo http://www.domain.com/html.asp | sed -e 's/\([\.a-zA-Z0-9]+[a-zA-Z]{2,3}\ >)/\1 /g' > >But that's not what sh thinks ( it returns the whole url ) >What regexp should I use to get the desired result? Here's a perl 1-liner: echo http://www.domain.com/html.asp |\ perl -e '$u=<>; $u=~s/http:\/\///; $u=~s/^www.//i; $u=~s/\/.*$//; print $u' domain.com This works in stages, so it doesn't depending on the starting string always containing all syntactical elements. -Mitch To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message