bash - return only paragraph by filtering command ouput -
bash - return only paragraph by filtering command ouput -
is there way homecoming sec or third, 4th paragraph using grep
, awk
...?
how can lo
paragraph, know that's possible using command ifconfig lo
how if utilize other commands. output ifconfig
is:
eth0 link encap:ethernet hwaddr 00:25:22:b2:8b:0d inet addr:192.168.1.22 bcast:192.168.1.255 mask:255.255.255.0 inet6 addr: fe80::225:22ff:feb2:8b0d/64 scope:link broadcast running multicast mtu:1500 metric:1 rx packets:100979 errors:0 dropped:0 overruns:0 frame:0 tx packets:70753 errors:0 dropped:0 overruns:0 carrier:1 collisions:0 txqueuelen:1000 rx bytes:129240044 (129.2 mb) tx bytes:7355272 (7.3 mb) interrupt:29 lo link encap:local loopback inet addr:127.0.0.1 mask:255.0.0.0 inet6 addr: ::1/128 scope:host loopback running mtu:16436 metric:1 rx packets:0 errors:0 dropped:0 overruns:0 frame:0 tx packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 rx bytes:0 (0.0 b) tx bytes:0 (0.0 b)
you can filter either paragraph number or interface name using awk
.
for paragraph number specify record awk 'nr==1' rs=''
:
# first record $ ifconfig | awk 'nr==1' rs='' eth0 link encap:ethernet hwaddr 00:25:22:b2:8b:0d inet addr:192.168.1.22 bcast:192.168.1.255 mask:255.255.255.0 inet6 addr: fe80::225:22ff:feb2:8b0d/64 scope:link broadcast running multicast mtu:1500 metric:1 rx packets:100979 errors:0 dropped:0 overruns:0 frame:0 tx packets:70753 errors:0 dropped:0 overruns:0 carrier:1 collisions:0 txqueuelen:1000 rx bytes:129240044 (129.2 mb) tx bytes:7355272 (7.3 mb) interrupt:29 # sec record $ ifconfig | awk 'nr==2' rs='' lo link encap:local loopback inet addr:127.0.0.1 mask:255.0.0.0 inet6 addr: ::1/128 scope:host loopback running mtu:16436 metric:1 rx packets:0 errors:0 dropped:0 overruns:0 frame:0 tx packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 rx bytes:0 (0.0 b) tx bytes:0 (0.0 b)
if want filter interface name , not record number awk '$1=="eth0"' rs=''
:
# interface lo $ ifconfig | awk '$1=="lo"' rs='' lo link encap:local loopback inet addr:127.0.0.1 mask:255.0.0.0 inet6 addr: ::1/128 scope:host loopback running mtu:16436 metric:1 rx packets:0 errors:0 dropped:0 overruns:0 frame:0 tx packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 rx bytes:0 (0.0 b) tx bytes:0 (0.0 b) # interface eth0 $ ifconfig | awk '$1=="eth0"' rs='' eth0 link encap:ethernet hwaddr 00:25:22:b2:8b:0d inet addr:192.168.1.22 bcast:192.168.1.255 mask:255.255.255.0 inet6 addr: fe80::225:22ff:feb2:8b0d/64 scope:link broadcast running multicast mtu:1500 metric:1 rx packets:100979 errors:0 dropped:0 overruns:0 frame:0 tx packets:70753 errors:0 dropped:0 overruns:0 carrier:1 collisions:0 txqueuelen:1000 rx bytes:129240044 (129.2 mb) tx bytes:7355272 (7.3 mb) interrupt:29
but don't know wrong ifconfig eth0
or ifconfig lo
.
bash shell filter awk grep
Comments
Post a Comment