$ lspci -tv | grep -E 'Gigabit Network|Gigabit Ether| Ethernet' | grep -oP '(?<=^).*(?=Intel)'
+-01.0-[01-04]----00.0-[02-04]--+-01.0-[03]--+-00.0
| | +-00.1
| | +-00.2
| | \-00.3
| \-03.0-[04]--+-00.0
| \-00.1
+-1c.0-[05]----00.0
+-1c.1-[06]----00.0 我试图从这个树中获取使用PCI总线地址的NIC排序(时隙)。这些表示为给定行上的最后一个正则表达式\[[0-9a-ZA-Z]\],例如,[03],[04],[05],然后是它们后面的子标头,例如00.0, 00.1, 00.2 for [03]。
我的预期产出应该是:
03:00.0
03:00.1
03:00.2
03:00.3
04:00.0
04:00.1
05:00.0
06:00.0例如,我尝试过这个,但没有更进一步。我知道这很难看,任何有或没有pipes的解决方案都可以。
$ lspci -tv | grep -E 'Gigabit Network|Gigabit Ether| Ethernet' | grep -oP '(?<=\-).*(?=Intel)' | grep -oE '(\[[0-9a-ZA-Z]{2}\])|(\[[0-9a-ZA-Z]{2}\].*[0-9]{2}\.[0-9])|(^[0-0]{2}.[0-9])'
[03]--+-00.0
00.1
00.2
00.3
[04]--+-00.0
00.1
[05]----00.0
[06]----00.0lspci -tv输出。我只对网卡感兴趣。grep Network,但是还有其他的例子,上面写着Ethernet。
$ lspci -tv
-[0000:00]-+-00.0 Intel Corporation Skylake Host Bridge/DRAM Registers
+-01.0-[01-04]----00.0-[02-04]--+-01.0-[03]--+-00.0 Intel Corporation I350 Gigabit Network Connection
| | +-00.1 Intel Corporation I350 Gigabit Network Connection
| | +-00.2 Intel Corporation I350 Gigabit Network Connection
| | \-00.3 Intel Corporation I350 Gigabit Network Connection
| \-03.0-[04]--+-00.0 Intel Corporation I350 Gigabit Network Connection
| \-00.1 Intel Corporation I350 Gigabit Network Connection
+-02.0 Intel Corporation HD Graphics P530
+-13.0 Intel Corporation Sunrise Point-H Integrated Sensor Hub
+-14.0 Intel Corporation Sunrise Point-H USB 3.0 xHCI Controller
+-14.2 Intel Corporation Sunrise Point-H Thermal subsystem
+-16.0 Intel Corporation Sunrise Point-H CSME HECI #1
+-16.1 Intel Corporation Sunrise Point-H CSME HECI #2
+-17.0 Intel Corporation Sunrise Point-H SATA controller [AHCI mode]
+-1c.0-[05]----00.0 Intel Corporation I210 Gigabit Network Connection
+-1c.1-[06]----00.0 Intel Corporation I210 Gigabit Network Connection
+-1c.6-[07-08]----00.0-[08]----00.0 ASPEED Technology, Inc. ASPEED Graphics Family
+-1f.0 Intel Corporation Sunrise Point-H LPC Controller
+-1f.2 Intel Corporation Sunrise Point-H PMC
\-1f.4 Intel Corporation Sunrise Point-H SMBus发布于 2018-09-25 17:30:53
使用GNU作为第三位arg到match()
$ cat tst.awk
!/Network|Ethernet/ { next }
match($0,/.*\[([0-9]+)\]/,a) {
nic = a[1]
}
match($0,/.*[+-\\]-([0-9]+\.[0-9]+) /,a) {
print nic ":" a[1]
}
$
$ awk -f tst.awk file
03:00.0
03:00.1
03:00.2
03:00.3
04:00.0
04:00.1
05:00.0
06:00.0https://stackoverflow.com/questions/52500697
复制相似问题