在这里,每个段落
我正在寻找这个问题的解决方案。我得到了一个带有输出的文件,如下所示:
Memory Device
Array Handle: 0x00E2
Error Information Handle: No Error
Total Width: 32 bits
Data Width: 32 bits
Size: 512 MB
Form Factor: DIMM
Set: None
Locator: RAM slot #0
Bank Locator: RAM slot #0
Type: DRAM
Type Detail: EDO
Speed: Unknown
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Memory Device
Array Handle: 0x00E2
Error Information Handle: No Error
Total Width: Unknown
Data Width: Unknown
Size: No Module Installed
Form Factor: DIMM
Set: None
Locator: RAM slot #1
Bank Locator: RAM slot #1
Type: DRAM
Type Detail: Unknown
Speed: Unknown
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Memory Device
Array Handle: 0x00E2
Error Information Handle: No Error
Total Width: Unknown
Data Width: Unknown
Size: No Module Installed
Form Factor: DIMM
Set: None
Locator: RAM slot #2
Bank Locator: RAM slot #2
Type: DRAM
Type Detail: Unknown
Speed: Unknown
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Memory Device
Array Handle: 0x00E2
Error Information Handle: No Error
Total Width: Unknown
Data Width: Unknown
Size: No Module Installed
Form Factor: DIMM
Set: None
Locator: RAM slot #3
Bank Locator: RAM slot #3
Type: DRAM
Type Detail: Unknown
Speed: Unknown
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
在这里,每个段落
都以"存储设备"开头,因此我想搜索每个带有数值的"大小"列的段落,并仅打印这些段落。因此,我不需要打印任何大小值为"大小:未安装模块"的段落。这是命令 "dmidecode --type memory"
的部分输出。谢谢你帮助我。
前提是输出的格式始终与您可以执行的操作相同
grep -E '[[:blank:]]Size: [0-9]+' mem.txt -A 11 -B 6
[编辑] -B 10 之所以有效,只是因为只有第一个条目具有数字大小。 -B 6 应该工作得更好。感谢您的评论。