Separating Fields from Output - cut command
Posted: Sat Aug 28, 2010 1:50 pm
Hi,
I want to display only the IP Address Value 10.0.2.15 from the output of:
as given below:
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:
But can we have a better approach?
I want to display only the IP Address Value 10.0.2.15 from the output of:
Code: Select all
ifconfig eth0 | grep "inet addr"Code: Select all
[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 ~]# 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:
Code: Select all
[root@localhost ~]# ifconfig eth0 | grep "inet addr" | cut -d: -f2 | cut -d" " -f1
10.0.2.15
[root@localhost ~]#