LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 06-22-2007, 11:27 AM   #1
sang_froid
Member
 
Registered: Oct 2006
Posts: 179

Rep: Reputation: 15
shell programming problem


Hi
After the user inputs the fully qualified domain name, say test.com.au or download.test.com.au, I would like to extract only the hostname, ie without com.au.



the thing is user might input something as test.com.au or download.test.com.au, but i simply need test and download.test

How do I do this with cut command ( it needs to be done in shell programming)
 
Old 06-22-2007, 11:35 AM   #2
Hobbletoe
Member
 
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 17
Posts: 150

Rep: Reputation: 18
Assuming that it is going into a variable such as site (as well as assuming that your shell is bash), you can use parameter substitution. ${site/com\.au/} should strip the com.au off of the variable whenever used. Check out the Advanced Bash Scipting Guide, specifically, Section 9.3.
 
Old 06-22-2007, 11:44 AM   #3
sang_froid
Member
 
Registered: Oct 2006
Posts: 179

Original Poster
Rep: Reputation: 15
i am all set...thanks
 
Old 06-25-2007, 06:00 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
delete everything after the first dot:

Code:
echo $x
test.blah.com.au

$ echo ${x%%.*}
test
 
  


Reply



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
shell programming problem ratul_11 Programming 6 12-20-2005 07:29 AM
shell programming problem ratul_11 Programming 2 12-15-2005 12:05 AM
shell programming problem ratul_11 *BSD 2 12-14-2005 12:47 PM
shell script programming problem newbie_ken Programming 5 08-16-2004 11:19 AM

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

All times are GMT -5. The time now is 06:20 AM.

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