如何使用awk或grep从文件中提取节

时间:2017-03-24 15:05:28

标签: bash awk

我正在处理需要从ESXi从smbiosDump中提取一些信息的脚本。 smbiosDump看起来像这样:

Dumping live SMBIOS data!
BIOS Info: #0
 Size: 0x00018
 Vendor: "FUJITSU // American Megatrends Inc."
 Version: "V5.0.0.11 R1.2.0 for D3373-B1x"
 Date: "03/16/2017"
 Start Address: 0xf0000
 ROM Size: 16384 kB
Features: 0x0d03000000013c099880
  PCI supported
  BIOS flashable
  BIOS shadowing allowed
  CD boot supported
  Selectable boot supported
  EDD spec supported
  Print Screen supported
  8042 Keyboard Services supported
  Serial Services supported
  Printer Services supported
  ACPI supported
  USB Legacy supported
  BIOS Boot Spec supported
  Enable targeted content distribution
  UEFI supported
System BIOS release: 1.2
Port Connector: #4
 Type: 0x08 (Serial Port 16550 Compatible)
 Internal Designator: "Serial"
 External Designator: "Serial 1"
 External Connector: 0x08 (DB-9 pin male)
Port Connector: #5
 Type: 0x1c (Video Port)
 Internal Designator: "VGA"
 External Designator: "Rear: Video"
 External Connector: 0x07 (DB-15 pin female)
Port Connector: #6
 Type: 0x1f (Network Port)
 Internal Designator: "LAN i210-AT"
 External Designator: "LAN 1"
 External Connector: 0x0b (RJ-45)
Port Connector: #7
 Type: 0x1f (Network Port)
 Internal Designator: "LAN i210-AT"
 External Designator: "LAN 2"
 External Connector: 0x0b (RJ-45)
Port Connector: #8
 Type: 0x1f (Network Port)
 Internal Designator: "iRMC-S4"
 External Designator: "LAN M"
 External Connector: 0x0b (RJ-45)
Port Connector: #9
 Type: 0x10 (USB)
 Internal Designator: "USB 2.0 REAR"
 External Designator: "Rear: USB 1"
 External Connector: 0x12 (Access Bus [USB])
Port Connector: #10
 Type: 0x10 (USB)
 Internal Designator: "USB 2.0 REAR"
 External Designator: "Rear: USB 2"
 External Connector: 0x12 (Access Bus [USB])
Port Connector: #11
 Type: 0x10 (USB)
 Internal Designator: "USB 2.0 REAR"
 External Designator: "Rear: USB 3"
 External Connector: 0x12 (Access Bus [USB])
Port Connector: #12
 Type: 0x20 (SATA)
 Internal Designator: "SATA 1-4"
 Internal Connector: 0xff (Other)
Port Connector: #13
 Type: 0x20 (SATA)
 Internal Designator: "SATA 5 DOM"
 Internal Connector: 0x22 (Other)
Port Connector: #14
 Type: 0x20 (SATA)
 Internal Designator: "SATA 6 DOM"
 Internal Connector: 0x22 (Other)
Port Connector: #15
 Type: 0x10 (USB)
 Internal Designator: "UFM"
 Internal Connector: 0xff (Other)
Port Connector: #16
 Type: 0x10 (USB)
 Internal Designator: "DAT"
 Internal Connector: 0x12 (Access Bus [USB])
Port Connector: #17
 Type: 0xff (Other)
 Internal Designator: "TPM HDR"
 Internal Connector: 0xff (Other)
System Slot: #18
 Designation: "SLOT 1"
 Type: 0xa5 (PCI Express)
 Bus Width: 0x08 (x1)
 Status: 0x03 (Available)
 Length: 0x03 (Short)
 Slot ID: 1
 Characteristics: 0x0104 (3.3 V, PME#)
System Slot: #19
 Designation: "SLOT2"
 Type: 0xa5 (PCI Express)
 Bus Width: 0x0a (x4)
 Status: 0x04 (In Use)
 Length: 0x03 (Short)
 Slot ID: 2
 Characteristics: 0x0104 (3.3 V, PME#)
System Slot: #20
 Designation: "SLOT3"
 Type: 0xa5 (PCI Express)
 Bus Width: 0x0b (x8)
 Status: 0x04 (In Use)
 Length: 0x03 (Short)
 Slot ID: 3
 Characteristics: 0x0104 (3.3 V, PME#)
System Slot: #21
 Designation: "SLOT4"
 Type: 0xa5 (PCI Express)
 Bus Width: 0x0b (x8)
 Status: 0x04 (In Use)
 Length: 0x03 (Short)
 Slot ID: 4
 Characteristics: 0x010c (3.3 V, Shared, PME#)
On Board Devices: #22
 Video: "VGA iRMC4"
 Ethernet: "LAN i210-AT"
 Ethernet: "LAN i210-AT"
OEM Strings: #23
 FUJITSU
 FUJITSU
 FUJITSU TECHNOLOGY SOLUTIONS
System Config Options (Jumpers & Switches) #24:
 PWD-CLR: Password Skip active
 RCVR: Recovery BIOS active
Hardware Security: #25
 Power-on Password: 0x00 (Disabled)
 Keyboard Password: 0x02 (Not Implemented)
 Admin Password: 0x00 (Disabled)
 Front Panel Reset: 0x02 (Not Implemented)
Type 32 Record: #26
 Data 00: 20 14 1a 00 00 00 00 00 00 00 00 00 00 00 00 00
 Data 10: 00 00 00 00
Type 41 Record: #27
 Data 00: 29 0b 1b 00 01 83 01 00 00 03 00
 String 1: "VGA iRMC4"
Type 41 Record: #28
 Data 00: 29 0b 1c 00 01 85 01 00 00 04 00
 String 1: "LAN i210-AT"
Type 41 Record: #29
 Data 00: 29 0b 1d 00 01 85 02 00 00 05 00
 String 1: "LAN i210-AT"
Type 38 Record: #30
 Data 00: 26 12 1e 00 01 20 20 ff a3 0c 00 00 00 00 00 00
 Data 10: 00 00
Cache Info: #31
 Designation: "L1 Cache"
 Level: L1
 State: Enabled
 Mode: 0x00 (Write Through)
 Location: 0x00 (Internal, Not Socketed)
 ECC: 0x02 (Unknown)
 Type: 0x04 (Data)
 Associativity: 0x07 (8-way Set-Associative)
 Max. Size: 128 kB
 Current Size: 128 kB
 Supported SRAM Types: 0x0002 (Unknown)
 Current SRAM Type: 0x0002 (Unknown)
Cache Info: #32
 Designation: "L1 Cache"
 Level: L1
 State: Enabled
 Mode: 0x00 (Write Through)
 Location: 0x00 (Internal, Not Socketed)
 ECC: 0x02 (Unknown)
 Type: 0x03 (Instruction)
 Associativity: 0x07 (8-way Set-Associative)
 Max. Size: 128 kB
 Current Size: 128 kB
 Supported SRAM Types: 0x0002 (Unknown)
 Current SRAM Type: 0x0002 (Unknown)
Cache Info: #33
 Designation: "L2 Cache"
 Level: L2
 State: Enabled
 Mode: 0x00 (Write Through)
 Location: 0x00 (Internal, Not Socketed)
 ECC: 0x05 (Single-bit)
 Type: 0x05 (Unified)
 Associativity: 0x05 (4-way Set-Associative)
 Max. Size: 1024 kB
 Current Size: 1024 kB
 Supported SRAM Types: 0x0002 (Unknown)
 Current SRAM Type: 0x0002 (Unknown)
Cache Info: #34
 Designation: "L3 Cache"
 Level: L3
 State: Enabled
 Mode: 0x01 (Write Back)
 Location: 0x00 (Internal, Not Socketed)
 ECC: 0x05 (Single-bit)
 Type: 0x05 (Unified)
 Associativity: 0x09 (12-way Set-Associative)
 Max. Size: 6144 kB
 Current Size: 6144 kB
 Supported SRAM Types: 0x0002 (Unknown)
 Current SRAM Type: 0x0002 (Unknown)
Processor Info: #35
 Payload length: 0x30
 Socket: "CPU1"
 Socket Type: 0x01 (Other)
 Socket Status: Populated
 Type: 0x03 (CPU)
 Family: 0xb3 (Xeon)
 Manufacturer: "Intel(R) Corporation"
 Version: "Intel(R) Xeon(R) CPU E3-1280 v6 @ 3.90GHz"
 Processor ID: 0xbfebfbff000906e9
 Status: 0x01 (Enabled)
 Voltage: 1.1 V
 External Clock: 100 MHz
 Max. Speed: 4200 MHz
 Current Speed: 3900 MHz
 L1 Cache: #32
 L2 Cache: #33
 L3 Cache: #34
 Core Count: #4
 Core Enabled Count: #4
 Thread Count: #8
Physical Memory Array: #36
 Use: 0x03 (System memory)
 Location: 0x03 (Motherboard)
 Slots: 4
 Max. Size: 64 GB
 ECC: 0x05 (Single-bit)
Memory Device: #37
 Location: "DIMM CHA3"
 Bank: "BANK 0"
 Manufacturer: "Samsung"
 Serial: "002FEFAAF"
 Asset Tag: "0123456789"
 Part Number: "M391A1K43BB1-CRC"
 Memory Array: #36
 Form Factor: 0x09 (DIMM)
 Type: 0x1a (DDR4)
 Type Detail: 0x0080 (Synchronous)
 Data Width: 64 bits (+8 ECC bits)
 Size: 8 GB
 Speed: 2400 MHz
Memory Device: #38
 Location: "DIMM CHA1"
 Bank: "BANK 1"
 Manufacturer: "Samsung"
 Serial: "002FEFABA"
 Asset Tag: "0123456789"
 Part Number: "M391A1K43BB1-CRC"
 Memory Array: #36
 Form Factor: 0x09 (DIMM)
 Type: 0x1a (DDR4)
 Type Detail: 0x0080 (Synchronous)
 Data Width: 64 bits (+8 ECC bits)
 Size: 8 GB
 Speed: 2400 MHz
Memory Device: #39
 Location: "DIMM CHB4"
 Bank: "BANK 2"
 Manufacturer: "Samsung"
 Serial: "002FEFB14"
 Asset Tag: "0123456789"
 Part Number: "M391A1K43BB1-CRC"
 Memory Array: #36
 Form Factor: 0x09 (DIMM)
 Type: 0x1a (DDR4)
 Type Detail: 0x0080 (Synchronous)
 Data Width: 64 bits (+8 ECC bits)
 Size: 8 GB
 Speed: 2400 MHz
Memory Device: #40
 Location: "DIMM CHB2"
 Bank: "BANK 3"
 Manufacturer: "Samsung"
 Serial: "002FEFAB7"
 Asset Tag: "0123456789"
 Part Number: "M391A1K43BB1-CRC"
 Memory Array: #36
 Form Factor: 0x09 (DIMM)
 Type: 0x1a (DDR4)
 Type Detail: 0x0080 (Synchronous)
 Data Width: 64 bits (+8 ECC bits)
 Size: 8 GB
 Speed: 2400 MHz
Memory Array Mapping: #41
 Memory Array: #36
 Partition Width: 4
 Start Address: 0x0000000000000000
 End Address: 0x0000000800000000
Type 176 Record: #42
 Data 00: b0 24 2a 00 00 00 73 33 00 11 33 00 02 31 ff ff
 Data 10: 72 fd ad 6a 08 39 a4 89 04 46 a1 4d f9 4a 28 3f
 Data 20: 01 00 01 00
Type 177 Record: #43
 Data 00: b1 2a 2b 00 12 00 00 00 12 00 00 00 12 05 00 00
 Data 10: 0b 01 02 00 00 00 00 00 00 00 00 12 00 00 00 00
 Data 20: 00 00 00 00 00 00 00 00 00 00
Type 188 Record: #44
 Data 00: bc 08 2c 00 30 39 31 24
Type 136 Record: #45
 Data 00: 88 06 2d 00 5a 5a
System Info: #46
 Manufacturer: "FUJITSU"
 Product: "PRIMERGY TX1320 M3"
 Serial: "YMBK000042"
 UUID: 09000800070006000500040003000200
 Wake-up: 0x06 (Power Switch)
Board Info: #47
 Manufacturer: "FUJITSU"
 Product: "D3373-B1"
 Version: "S26361-D3373-B12 WGS03 GS51"
 Serial: "50896663"
 Type: 0x0a (Motherboard)
 Features: 0x09
  Hosting Board
  Replaceable
 Chassis: #3
Chassis Info: #48
 Manufacturer: "FUJITSU"
 Version: "TX1320M3F5"
 Serial: "YMBK000042"
 Asset Tag: "System Asset Tag"
 Type: 0x11 (Main Server Chassis)
 Bootup State: 0x03 (Safe)
 Power Supply State: 0x03 (Safe)
 Thermal State: 0x03 (Safe)
 Security Status: 0x03 (None)
Memory Device Mapping: #49
 Memory Device: #37
 Array Mapping: #41
 Interleave Pos: 1
 Interleaved Depth: 2
 Start Address: 0x0000000000000000
 End Address: 0x0000000200000000
Memory Device Mapping: #50
 Memory Device: #38
 Array Mapping: #41
 Interleave Pos: 1
 Interleaved Depth: 2
 Start Address: 0x0000000400000000
 End Address: 0x0000000600000000
Memory Device Mapping: #51
 Memory Device: #39
 Array Mapping: #41
 Interleave Pos: 2
 Interleaved Depth: 2
 Start Address: 0x0000000200000000
 End Address: 0x0000000400000000
Memory Device Mapping: #52
 Memory Device: #40
 Array Mapping: #41
 Interleave Pos: 2
 Interleaved Depth: 2
 Start Address: 0x0000000600000000
 End Address: 0x0000000800000000
Type 221 Record: #53
 Data 00: dd 1a 35 00 03 01 00 04 01 00 01 00 02 00 00 00
 Data 10: 00 48 00 03 00 00 05 00 00 00
 String 1: "Reference Code - CPU"
 String 2: "uCode Version"
 String 3: "TXT ACM version"
Type 221 Record: #54
 Data 00: dd 44 36 00 09 01 00 04 01 00 01 00 02 03 ff ff
 Data 10: ff ff ff 04 00 ff ff ff 31 00 05 00 ff ff ff 31
 Data 20: 00 06 00 ff ff ff ff ff 07 00 3e 00 00 00 00 08
 Data 30: 00 34 00 00 00 00 09 00 3e 00 00 00 00 0a 00 34
 Data 40: 00 00 00 00
 String 1: "Reference Code - SKL PCH"
 String 2: "PCH-CRID Status"
 String 3: "Disabled"
 String 4: "PCH-CRID Original Value"
 String 5: "PCH-CRID New Value"
 String 6: "OPROM - RST - RAID"
 String 7: "SKL PCH H Bx Hsio Version"
 String 8: "SKL PCH H Dx Hsio Version"
 String 9: "SKL PCH LP Bx Hsio Version"
 String 10: "SKL PCH LP Cx Hsio Version"
Type 221 Record: #55
 Data 00: dd 36 37 00 07 01 00 04 01 00 01 00 02 00 04 01
 Data 10: 00 01 00 03 00 04 01 00 00 00 04 05 ff ff ff ff
 Data 20: ff 06 00 ff ff ff 05 00 07 00 ff ff ff 05 00 08
 Data 30: 00 ff ff ff ff ff
 String 1: "Reference Code - SA - System Agent"
 String 2: "Reference Code - MRC"
 String 3: "SA - PCIe Version"
 String 4: "SA-CRID Status"
 String 5: "Disabled"
 String 6: "SA-CRID Original Value"
 String 7: "SA-CRID New Value"
 String 8: "OPROM - VBIOS"
Type 221 Record: #56
 Data 00: dd 60 38 00 0d 01 00 00 00 00 00 00 02 00 ff ff
 Data 10: ff ff ff 03 04 ff ff ff ff ff 05 06 ff ff ff ff
 Data 20: ff 07 08 ff ff ff ff ff 09 00 00 00 00 00 00 0a
 Data 30: 00 ff ff ff ff 00 0b 00 ff ff 00 00 00 0c 00 ff
 Data 40: ff ff ff ff 0d 00 ff ff ff ff ff 0e 00 ff ff ff
 Data 50: ff ff 0f 00 ff ff ff ff ff 10 11 01 02 02 03 00
 String 1: "Lan Phy Version"
 String 2: "Sensor Firmware Version"
 String 3: "Debug Mode Status"
 String 4: "Disabled"
 String 5: "Performance Mode Status"
 String 6: "Disabled"
 String 7: "Debug Use USB(Disabled:Serial)"
 String 8: "Disabled"
 String 9: "ICC Overclocking Version"
 String 10: "UNDI Version"
 String 11: "EC FW Version"
 String 12: "GOP Version"
 String 13: "BIOS Guard Version"
 String 14: "Base EC FW Version"
 String 15: "EC-EC Protocol Version"
 String 16: "Royal Park Version"
 String 17: "BP1.2.2.0_RP03"
Group Associations: #57
 Group Name: "Firmware Version Info"
 Items: #53, #54, #55, #56
Language Info: #58
 Languages: en|US|iso8859-1
 Current: en|US|iso8859-1

在不同的系统上,转储是不同的,更长或更短。 我需要从这个转储文件和其他类似的转储文件,L1(或L2或L3)Cache Max中提取一些信息。尺寸信息。并打印出这样的东西:

Level: L1
Max Size: 128 kb

我还要注意,每个系统的缓存信息编号(#32,#31等)都不同。这里的#31在另一个系统上可能是#41,或#29。因此,不幸的是,尝试将编号用作过滤器将无法正常工作。

(对于L2或L3也是如此,但在不同的脚本上。) (由于我原来的问题,我不得不发一个新帖子,这是另一页:How can I extract a section of a file based on matching only one line?

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

您可以将转储管道传输到egrep

…|egrep 'Level|Max. Size'

这将仅选择包含LevelMax. Size

的行

如果您不想手动删除与Max. Size无法关联的Level行,则可以进一步管道awk

…|egrep 'Level|Max. Size'|awk '$1!=prevline{print $0}{prevline=$1;}'

这将检查第一个单词($1)是否与prevline中的单词不同,然后打印整行,并将第一个单词存储在prevline中。