我正在编写一行代码来从 Incus 获取 GPU 的 PCI 地址。以下是该命令第一部分的输出:
incus info --resources | grep -E 'GPU:|GPUs:' -A 20
GPUs:
Card 0:
NUMA node: 0
Vendor: ASPEED Technology, Inc. (1a03)
Product: ASPEED Graphics Family (2000)
PCI address: 0000:22:00.0
Driver: ast (6.12.9-production+truenas)
DRM:
ID: 0
Card: card0 (226:0)
Control: controlD64 (226:0)
Card 1:
NUMA node: 0
Vendor: NVIDIA Corporation (10de)
Product: GP102 [GeForce GTX 1080 Ti] (1b06)
PCI address: 0000:2b:00.0
Driver: nvidia (550.142)
DRM:
ID: 1
Card: card1 (226:1)
Render: renderD128 (226:128)
NVIDIA information:
Architecture: 6.1
Brand: GeForce
Model: NVIDIA GeForce GTX 1080 Ti
CUDA Version: 12.4
NVRM Version: 550.142
UUID: GPU-9d45b825-9a28-afab-1189-e071779f7469
我使用grep
将其限制为'amd|intel|nvidia'
,awk
打印PCI Address:
,然后sed
删除空格。我一直得到一个尾随的哈希(#
)字符,它实际上是从 生成的printf
。printf
会自动为我删除所有额外的字符newlines
。但是,我还没有找到一种方法来消除哈希字符。我在这里遗漏了什么?如果有更好的方法,我也会接受。谢谢!
incus info --resources | grep -E 'GPU:|GPUs:' -A 20 | grep -Ei 'amd|intel|nvidia' -A 20 | awk -F "PCI address:" '{printf $2}' | sed 's/ //'
0000:2b:00.0#
编辑:简而言之,为了增加一些清晰度,我只需要从、或PCI Address:
之一中获取并输出 PCI 地址:仅。amd
intel
nvidia