The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
doubt in awk jisha Shell Programming and Scripting 4 04-16-2008 05:02 AM
AWK doubt Rafael.Buria Shell Programming and Scripting 2 02-06-2008 11:00 AM
doubt about awk soujanya_srk UNIX for Dummies Questions & Answers 2 01-10-2008 05:26 PM
SDL doubt royalibrahim High Level Programming 0 11-22-2007 01:49 AM
ftp doubt ranj@chn Shell Programming and Scripting 0 01-04-2006 08:47 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-13-2005
esham's Avatar
esham esham is offline
Registered User
  
 

Join Date: Nov 2004
Location: INDIA
Posts: 107
awk doubt..

Hello,

Iam trying to get the IP of the hostname of the machine from /etc/hosts.
I used the command as below:
Quote:
awk "/$(hostname)/ {print $1}" /etc/hosts
But the result shows the IP with the hostname..
like

192.168.0.8 test12111.com

I need to get only 192.168.0.8

Please help
Thanks in advance
esham
  #2 (permalink)  
Old 03-13-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Code:
nawk -v i=$(hostname) '$0 ~ i {print $1}' /etc/hosts
  #3 (permalink)  
Old 03-13-2005
tanku tanku is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 53
another way,

cat /etc/hosts|grep $HOSTNAME|awk '{print $1}'

Last edited by tanku; 03-13-2005 at 09:26 AM..
  #4 (permalink)  
Old 03-13-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Quote:
Originally Posted by tanku
another way,

cat /etc/hosts|grep $HOSTNAME|awk '{print $1}'
UUOC

grep "${HOSTNAME}" /etc/hosts |awk '{print $1}'
  #5 (permalink)  
Old 03-13-2005
tanku tanku is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 53
it's not useless! it's clean
  #6 (permalink)  
Old 03-13-2005
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Quote:
Originally Posted by tanku
it's not useless! it's clean
#define clean ???
  #7 (permalink)  
Old 03-13-2005
esham's Avatar
esham esham is offline
Registered User
  
 

Join Date: Nov 2004
Location: INDIA
Posts: 107
Thanks for all replies..
All worked great..

But let me know what made my script wrong..
Quote:
awk "/$(hostname)/ {print $1}" /etc/hosts
anybody please explain...
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0