|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 > It's hard to tell how much of the formatting above is due to linewrapping in your posting, but try this: awk 'key ~ /^c/{print key,$2} {key = sub(/:$/,"",$1) ? $1 : ""}' Ed. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Ed Morton wrote:
> 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 >> > > It's hard to tell how much of the formatting above is due to > linewrapping in your posting, but try this: > > awk 'key ~ /^c/{print key,$2} {key = sub(/:$/,"",$1) ? $1 : ""}' > > Ed. Each interface has got 2 or more lines actually. Consecutive lines are indented. The question would fit better for comp.unix.admin or comp.unix.solaris -- Michael Tosch @ hp : com |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
In article <1180503661.602541.126320@q69g2000hsb.googlegroups .com>,
<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,DEPR ECATED,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 > from the dirty tricks department: ifconfig -a \ awk '/flags/ {sub(":$","",$1);f=$1;} /inet/ {printf ("%s\t%s\n",f,$2)}' Note: This will generate a separate, full, line for each address assigned to an interface with multiple addresses. |
|
![]() |
| Outils de la discussion | |
|
|