当前位置: 技术问答>linux和unix
linux下如何用脚本从文件中得到我感兴趣的东西!熟悉linux下脚本的一定要看呀!
来源: 互联网 发布时间:2015-10-23
本文导语: 我在linux下用ifconfig >/tmp/MAC 把ifconfig的内容输出到/tmp/MAC文件中,下面的是文件的内容 -------------------------------------------------------------------- eth0 Link encap:Ethernet HWaddr 00:0B:DB:55:D3:FB inet addr:3.3...
我在linux下用ifconfig >/tmp/MAC 把ifconfig的内容输出到/tmp/MAC文件中,下面的是文件的内容
--------------------------------------------------------------------
eth0 Link encap:Ethernet HWaddr 00:0B:DB:55:D3:FB
inet addr:3.36.231.203 Bcast:3.36.231.255 Mask:255.255.252.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7201258 errors:0 dropped:0 overruns:0 frame:0
TX packets:5418609 errors:22 dropped:0 overruns:0 carrier:22
collisions:1893928 txqueuelen:100
RX bytes:2138257840 (2039.2 Mb) TX bytes:861082042 (821.1 Mb)
Interrupt:10 Base address:0xecc0 Memory:ff8e0000-ff900000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8882882 errors:0 dropped:0 overruns:0 frame:0
TX packets:8882882 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1237750393 (1180.4 Mb) TX bytes:1237750393 (1180.4 Mb)
------------------------------------------------------------------------------
现在的问题是我将如何得到00:0B:DB:55:D3:FB这个网卡标号呢?在此先谢谢大家!
--------------------------------------------------------------------
eth0 Link encap:Ethernet HWaddr 00:0B:DB:55:D3:FB
inet addr:3.36.231.203 Bcast:3.36.231.255 Mask:255.255.252.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7201258 errors:0 dropped:0 overruns:0 frame:0
TX packets:5418609 errors:22 dropped:0 overruns:0 carrier:22
collisions:1893928 txqueuelen:100
RX bytes:2138257840 (2039.2 Mb) TX bytes:861082042 (821.1 Mb)
Interrupt:10 Base address:0xecc0 Memory:ff8e0000-ff900000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8882882 errors:0 dropped:0 overruns:0 frame:0
TX packets:8882882 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1237750393 (1180.4 Mb) TX bytes:1237750393 (1180.4 Mb)
------------------------------------------------------------------------------
现在的问题是我将如何得到00:0B:DB:55:D3:FB这个网卡标号呢?在此先谢谢大家!
|
一定要用脚本完成?
|
cat tmp.txt|grep eth0|awk {'print $5'}
|
ifconfig |awk '/eth0/ {print $5}'
$MAC=$(ifconfig |awk '/eth0/ {print $5}')
$MAC=$(ifconfig |awk '/eth0/ {print $5}')