标签:mask 17.1 packet 文件的 == byte inet6 scope int
1、打印文件的第一列(域) : awk ‘{print $1}‘ filename
2、打印文件的前两列(域) : awk ‘{print $1,$2}‘ filename
3、打印完第一列,然后打印第二列 : awk ‘{print $1 $2}‘ filename
4、打印文本文件的总行数 : awk ‘END{print NR}‘ filename
5、打印文本第一行 :awk ‘NR==1{print}‘ filename
6、打印文本第二行第一列 :sed -n "2, 1p" filename | awk ‘print $1‘
例如: [root@jump_154 guoguo]# ifconfig eth2 eth2 Link encap:Ethernet HWaddr A0:36:9F:46:76:92 inet addr:192.168.192.100 Bcast:192.168.192.255 Mask:255.255.255.0 inet6 addr: fe80::a236:9fff:fe46:7692/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:122877 errors:0 dropped:0 overruns:0 frame:0 TX packets:612386 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:17982672 (17.1 MiB) TX bytes:27648420 (26.3 MiB) Memory:d5b00000-d5bfffff 如果想获取eth2 的ip地址 可以直接用sed 实现 [root@jump_154 guoguo]# ifconfig eth2 |grep ‘inet‘|sed s/^.*addr://g |sed s/Bcast.*$//g 192.168.192.100 fe80::a236:9fff:fe46:7692/64 Scope:Link 发现出来2行,需要用sed 取第一行 [root@jump_154 guoguo# ifconfig eth2 |grep ‘inet‘|sed -n "1p"|sed s/^.*addr://g |sed s/Bcast.*$//g 192.168.192.100 当然也可以结合awk实现 [root@jump_154 guoguo]# ifconfig eth2 |grep ‘inet‘|awk ‘NR==1{print}‘|sed s/^.*addr://g |sed s/Bcast.*$//g 192.168.192.100 [root@jump_154 guoguo]# ifconfig eth2 |grep ‘inet‘|awk {‘print $2‘}|sed s/^.*addr://g 192.168.192.100
标签:mask 17.1 packet 文件的 == byte inet6 scope int
原文地址:http://www.cnblogs.com/sxwen/p/7953810.html