PHP Developers Network
http://forums.devnetwork.net/

Separating Fields from Output - cut command
http://forums.devnetwork.net/viewtopic.php?f=30&t=120481
Page 1 of 1

Author:  devarishi [ Sat Aug 28, 2010 1:50 pm ]
Post subject:  Separating Fields from Output - cut command

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?

Author:  McInfo [ Fri Sep 03, 2010 5:57 pm ]
Post subject:  Re: Separating Fields from Output - cut command


Author:  Doug G [ Fri Sep 03, 2010 6:38 pm ]
Post subject:  Re: Separating Fields from Output - cut command

Thanks for the useful grep snip :)

Author:  McInfo [ Fri Sep 03, 2010 7:22 pm ]
Post subject:  Re: Separating Fields from Output - cut command


Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/