Bash脚本如何获取第二个属性及其特定值



我正试图从作为变量的命令中获得特定的输出。

这是命令:

hwinfo --disk 

输出:

11: None 00.0: 10600 Disk                                       
[Created at block.245]
Unique ID: +b7l.Fxp0d3BezAE
Parent ID: JaHa.j9MZgu1IFZ6
SysFS ID: /class/block/xvda
SysFS BusID: vbd-768
SysFS Device Link: /devices/vbd-768
Hardware Class: disk
Model: "Disk"
Driver: "vbd"
Driver Modules: "xen_blkfront"
Device File: /dev/xvda
Device Number: block 202:0-202:15
Drive status: no medium
Config Status: cfg=new, avail=yes, need=no, active=unknown
Attached to: #8 (Storage controller)
12: None 00.0: 10600 Disk
[Created at block.245]
Unique ID: SnNp.Fxp0d3BezAE
Parent ID: h6mc.j9MZgu1IFZ6
SysFS ID: /class/block/xvdb
SysFS BusID: vbd-51728
SysFS Device Link: /devices/vbd-51728
Hardware Class: disk
Model: "Disk"
Driver: "vbd"
Driver Modules: "xen_blkfront"
Device File: /dev/xvdb
Device Files: /dev/xvdb, /dev/disk/by-uuid/e6fc7a51-7f12-4b35-a48e-6cd2db77bcee
Device Number: block 202:16-202:31
Drive status: no medium
Config Status: cfg=new, avail=yes, need=no, active=unknown
Attached to: #10 (Storage controller)

我想将第二个属性保存为变量(12(,但只保存"0"的值;设备文件";在本例中/dev/xvdb";

有人能帮我吗?

这就是我成功地将先前输出中的特定值存储到变量中的方法。

hw=$(hwinfo --disk | grep 'Device File:' | cut -d ' ' -f5)
disk=$(echo $hw | cut -d ' ' -f2)
echo $disk 
/dev/xvdb

谢谢大家。

相关内容

  • 没有找到相关文章

最新更新