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
IP Address not found in ifconfig/netstat Isax50 IP Networking 1 02-08-2009 09:32 AM
script to get IP address from ifconfig speedy3k Shell Programming and Scripting 9 12-31-2008 12:54 AM
how to grep only IP address of e1000g0 using ifconfig -a solaix14 Shell Programming and Scripting 1 11-03-2008 03:28 PM
ifconfig: ce401001: bad address sag71155 IP Networking 2 06-19-2008 12:08 PM
ifconfig bad address ppass SUN Solaris 2 03-11-2005 07:59 AM

Reply
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 09-29-2009
manustone manustone is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 6
extracting the ip address from ifconfig

Hi
I am trying to create a script extracting the IP provided by ifconfig.
I tried with grep + awk but I am returned more than I need.


Code:
  
/sbin/ifconfig eth0 | grep "inet addr:" | awk '/inet addr:/ { print $2 }'

and returns


Code:
 
addr:10.15.1.64

How can I remove "addr:" string?
Thanks in advance
  #2 (permalink)  
Old 09-29-2009
danmero danmero is online now Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,449
awk can grep, no UUOC required.
Please post the output of

Code:
/sbin/ifconfig eth0

  #3 (permalink)  
Old 09-29-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
Quote:
Originally Posted by manustone View Post
Hi
I am trying to create a script extracting the IP provided by ifconfig.
I tried with grep + awk but I am returned more than I need.


Code:
  
/sbin/ifconfig eth0 | grep "inet addr:" | awk '/inet addr:/ { print $2 }'

and returns


Code:
 
addr:10.15.1.64

How can I remove "addr:" string?
Thanks in advance

Code:
A bit modification : 

/sbin/ifconfig eth0 | awk -F":" '/inet addr:/ { print $2 }'

  #4 (permalink)  
Old 09-29-2009
ainuddin ainuddin is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 15

Code:
/sbin/ifconfig eth0 | grep "inet addr:" | awk '/inet addr:/ { print $2 }' | cut -d":" -f2

or

Code:
/sbin/ifconfig eth0 | grep "inet addr:" | awk '/inet addr:/ { print $2 }' | awf -F":" '{print $2}'


Last edited by Franklin52; 09-29-2009 at 10:48 AM.. Reason: Please use code tags!
  #5 (permalink)  
Old 09-29-2009
ripat ripat is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 441
Depending ifconfig's o/p this should also work:

Code:
ifconfig eth0 | awk -F":| +" '/inet adr/{print $4}'

If it doesn't work, post ifconfig's o/p.
  #6 (permalink)  
Old 09-29-2009
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,350
Quote:
Originally Posted by ainuddin View Post
Code:
/sbin/ifconfig eth0 | grep "inet addr:" | awk '/inet addr:/ { print $2 }' | cut -d":" -f2

or

Code:
/sbin/ifconfig eth0 | grep "inet addr:" | awk '/inet addr:/ { print $2 }' | awf -F":" '{print $2}'

Using grep and cut with awk is redundant but piping the result of an awk output to awk is ...

  #7 (permalink)  
Old 09-29-2009
skmdu skmdu is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 125

Code:
$ ifconfig eth0 | perl -ne 'if ( /inet addr:(^\s]+)/) { print $1; }'

Reply

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 07:45 AM.


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