1. awk
详细参数说明
awk '{print $3,$4}' /proc/net/arp
把arp文件的第三行和第四行,打印出来,可以重定向到文件
root@OpenWrt:/tmp# awk '{print $3,$4}' /proc/net/arp >/tmp/net_arp_list
root@OpenWrt:/tmp# cat net_arp_list
HW type
0x2 28:ed:6a:e9:ab:fb
0x2 00:e0:4c:68:00:03
0x2 a4:44:d1:d6:d2:3f
root@OpenWrt:/tmp# cd /tmp/
root@OpenWrt:/tmp# ls
802.mt7603e.log extroot net_arp_list
802.mt7612e.log fastcgi.socket-0 overlay
root@OpenWrt:/tmp# cat /proc/net/arp
IP address HW type Flags HW address Mask Device
192.168.0.30 0x1 0x2 28:ed:6a:e9:ab:fb * br-lan
192.168.0.188 0x1 0x2 00:e0:4c:68:00:03 * br-lan
192.168.0.250 0x1 0x2 a4:44:d1:d6:d2:3f * br-lan
root@OpenWrt:/tmp# awk '{print $3,$4}' /proc/net/arp
HW type
0x2 28:ed:6a:e9:ab:fb
0x2 00:e0:4c:68:00:03
0x2 a4:44:d1:d6:d2:3f
2.cut
详细参数说明
cut -d ‘空格’ -f 1
以 ‘空格’ 为分隔符,选取第一个域里面的内容,输出
root@OpenWrt:/tmp# grep "28:ed:6a:e9:ab:fb" /tmp/net_arp_list
0x2 28:ed:6a:e9:ab:fb
root@OpenWrt:/tmp# grep "28:ed:6a:e9:ab:fb" /tmp/net_arp_list | cut -d ' ' -f 1
0x2
root@OpenWrt:/tmp#