Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i grep, sed, or awk hostnames form a fiile? 1

Status
Not open for further replies.

linuxMaestro

Instructor
Jan 12, 2004
183
US
I have a file that contains hostnames:
cache-mtc-ad03.proxy.aol.com
0 6 0 0 0 0
-

c175104.adsl.hansenet.de
0 88 85 11940960 1 1101887409
/members/archive/14-a6fn87xpan/vi/
cache-rtc-ac07.proxy.aol.com
0 20 18 1252115 0 0
-
cache-dtc-ac02.proxy.aol.com
0 22 19 84487 3 1101942368
/firsttime/archive/08/bh/
cpe00c09f1c6947-cm00003906405e.cpe.net.cable.rogers.com
0 1 1 51 1 1101904291

How can I get the hostnames only?
Ex.
cache-mtc-ad03.proxy.aol.com
cache-dtc-ac02.proxy.aol.com
c175104.adsl.hansenet.de
cpe00c09f1c6947-cm00003906405e.cpe.net.cable.rogers.com
 
A starting point:
awk 'NF==1 && $1~/\./' /path/to/input

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks can you describe this
awk: unix command
'/:
\:
.:
[a-z]:
[a-z]:
[a-z]:
?:
$:
/:
&&:
!:
/:
[:
:
\:
/:
]:
/':
infile: file to awk
 
[tt]
/\.[a-z][a-z][a-z]?$/
[/tt]
is a "regular expression". It matches, at the end of a line, a period followed by 2 or 3 lowercase letters. The next part:
[tt]
!/[ \/]/
[/tt]
is there to reject lines that contain a space or a slash.

For an introduction to Awk, see faq271-5564.

Let me know whether or not this helps.

If you have nawk, use it instead of awk because on some systems awk is very old and lacks many useful features. Under Solaris, use /usr/xpg4/bin/awk.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top