Seve.Paritos@gmail.com wrote:
> hello everyone.
> I have the following ifconfig output on solaris and want to be able to
> get the output from it in the following format using a one liner.
>
> ce0 192.168.13.50
> ce0:1 192.168.13.245
> ce0:2 192.168.13.64
> ce0:3 192.168.13.62
> ce1 192.168.13.51
>
> bash-2.05$ ifconfig -a
> lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index
> 3
> inet 127.0.0.1 netmask ff000000
> ce0:
> flags=9040843<UP,BROADCAST,RUNNING,MULTICAST,DEPRE CATED,IPv4,NOFAILOVER>
> mtu 1500 index 4
> inet 192.168.13.50 netmask fffffc00 broadcast 192.168.15.255
> groupname amazon_ipmp_bk
> ce0:1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500
> index 4
> inet 192.168.13.245 netmask fffffc00 broadcast 192.168.15.255
> ce0:2: flags=1000842<BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index
> 4
> inet 192.168.13.64 netmask fffffc00 broadcast 192.168.15.255
> ce0:3: flags=1000842<BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index
> 4
> inet 192.168.13.62 netmask fffffc00 broadcast 192.168.15.255
> ce1:
> flags=9040843<UP,BROADCAST,RUNNING,MULTICAST,DEPRE CATED,IPv4,NOFAILOVER>
> mtu 1500 index 5
> inet 192.168.13.51 netmask fffffc00 broadcast 192.168.15.255
> groupname amazon_ipmp_bk
>
> Thanks
>
ifconfig -a |
sed -n 'h;s/^\([^ ]*\):.*/\1/p;g;s/.*inet \([^ ]*\).*/\1/p'
awk has better formatting capabilities:
ifconfig -a |
awk '$1~/:$/ {s=$1} {for(i=1;i<NF;++i) if($i=="inet") print s,$(i+1)}'
printf "%s\t%s\n",substr(s,1,length(s)-1),$(i+1)
formats the output as TAB-separated, and the substr() eliminates the
trailing :
--
Michael Tosch @ hp : com