我尝试获取计算机上可用的所有无线接口。例如,如果我分别使用两个具有逻辑名称wlan0
和 的网卡, ra0
那么我想打印它们。
这是我尝试过的,但没有得到任何输出:
sudo lshw -C network | awk 'if (/description: / $2 == "Wireless") { /logical name: /{printf $3 "\n";}}'
我收到语法错误:
awk: line 1: syntax error at or near if
awk: line 1: syntax error at or near }
不带部分的输出awk
:
*-network
description: Network controller
product: BCM4313 802.11bgn Wireless Network Adapter
vendor: Broadcom Corporation
physical id: 0
bus info: pci@0000:05:00.0
version: 01
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress bus_master cap_list
configuration: driver=bcma-pci-bridge latency=0
resources: irq:17 memory:96400000-96403fff
*-network
description: Ethernet interface
product: RTL8101/2/6E PCI Express Fast/Gigabit Ethernet controller
vendor: Realtek Semiconductor Co., Ltd.
physical id: 0
bus info: pci@0000:06:00.0
logical name: enp6s0
version: 02
serial: 88:ae:1d:da:9e:99
size: 10Mbit/s
capacity: 100Mbit/s
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress msix vpd bus_master cap_list rom ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=r8169 driverversion=2.3LK-NAPI duplex=half latency=0 link=no multicast=yes port=MII speed=10Mbit/s
resources: irq:24 ioport:2000(size=256) memory:92410000-92410fff memory:92400000-9240ffff memory:95400000-9541ffff
*-network
description: Wireless interface
physical id: 3
logical name: wlp5s0b1
serial: 00:26:82:e7:b8:32
capabilities: ethernet physical wireless
configuration: broadcast=yes driver=brcmsmac driverversion=4.4.0-53-generic firmware=610.812 ip=192.168.0.14 link=yes multicast=yes wireless=IEEE 802.11bgn
更新:如果有更好的方法来获得我想要的东西,那么我很乐意接受这样的答案。
答案1
awk -F": " -v line=-1 '{if($2=="Wireless interface"){ line=NR+2}; if (line==NR){print $2}}' youfile
-F
设置分隔符-v
传递一个带有值的变量NR
电话号码
我得到后从第二行得到第二项"Wireless interface"