PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Nov 20, 2019 6:26 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Aug 28, 2010 1:50 pm 
Offline
Forum Contributor

Joined: Fri Feb 05, 2010 8:15 pm
Posts: 101
Hi,


I want to display only the IP Address Value 10.0.2.15 from the output of:

Syntax: [ Download ] [ Hide ]
ifconfig eth0 | grep "inet addr"


as given below:
Syntax: [ Download ] [ Hide ]
[root@localhost ~]# ifconfig eth0 | grep "inet addr"
         inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
[root@localhost ~]# ifconfig eth0 | grep "inet addr" | cut -d: -f2
10.0.2.15  Bcast
[root@localhost ~]#


but it is displaying the text "Bcast" as well.

The main problem here is that the first value and the second field / column name have no delimiter to separate them.



Okay, this one is working:

Syntax: [ Download ] [ Hide ]
[root@localhost ~]# ifconfig eth0 | grep "inet addr" | cut -d: -f2 | cut -d" " -f1
10.0.2.15
[root@localhost ~]#

 
But can we have a better approach?


Top
 Profile  
 
PostPosted: Fri Sep 03, 2010 5:57 pm 
Offline
DevNet Resident
User avatar

Joined: Wed Apr 01, 2009 1:31 pm
Posts: 1532


Top
 Profile  
 
PostPosted: Fri Sep 03, 2010 6:38 pm 
Offline
Forum Contributor

Joined: Sun Sep 09, 2007 6:27 pm
Posts: 282
Thanks for the useful grep snip :)


Top
 Profile  
 
PostPosted: Fri Sep 03, 2010 7:22 pm 
Offline
DevNet Resident
User avatar

Joined: Wed Apr 01, 2009 1:31 pm
Posts: 1532


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group