【命令】awk

来源:互联网 发布:足彩基本面分析软件 编辑:程序博客网 时间:2024/06/09 23:17

1.先用一个例子

我们需要获取eth0口的ip地址

ifconfig eth0eth0      Link encap:Ethernet  HWaddr 00:E0:4C:E6:4B:DA            inet addr:192.168.28.92  Bcast:192.168.28.255  Mask:255.255.252.0          inet6 addr: fe80::2e0:4cff:fee6:4bda/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:36006193 errors:0 dropped:0 overruns:0 frame:0          TX packets:1104312 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:114322034 (109.0 MiB)  TX bytes:1433060632 (1.3 GiB)          Interrupt:233 Base address:0x8000

ifconfig eth0 | grep -i bcast          inet addr:192.168.28.92  Bcast:192.168.28.255  Mask:255.255.252.0

ifconfig eth0 | grep -i bcast | awk -F: '{print $2}'192.168.28.92  Bcast

ifconfig eth0 | grep -i bcast | awk -F: '{print $2}' | awk -F " " '{print $1}'192.168.28.92

选项-F,表明将指定行中的字段用指定的分隔符进行分割

0 0