I have a file with multiple paragraphs/sections each starting with word "Handle" and if I grep for a pattern, I should get contents of entire section/para (not just line). Please advise, thanks!
#script.sh file.txt "System Information"
Handle 0x0001
DMI type 1, 27 bytes.
System Information
Manufacturer: VMware, Inc.
Product Name: VMware Virtual Platform
Version: None
Serial Number: VMware-50 2a 97 c6 3e 64 b4 f5-ec 9f 59 78 f3 5d 13 6a
UUID: 502A97C6-3E64-B4F5-EC9F-5978F35D136A
Wake-up Type: Power Switch
#cat file.txt
SMBIOS 2.4 present.
98 structures occupying 3681 bytes.
Table at 0x000E0010.
Handle 0x0000
DMI type 0, 24 bytes.
BIOS Information
Vendor: Phoenix Technologies LTD
Version: 6.00
Release Date: 04/15/2011
Address: 0xEA2E0
Runtime Size: 89376 bytes
ROM Size: 64 kB
Characteristics:
ISA is supported
PCI is supported
PC Card (PCMCIA) is supported
PNP is supported
APM is supported
BIOS is upgradeable
BIOS shadowing is allowed
ESCD support is available
USB legacy is supported
Smart battery is supported
BIOS boot specification is supported
Handle 0x0001
DMI type 1, 27 bytes.
System Information
Manufacturer: VMware, Inc.
Product Name: VMware Virtual Platform
Version: None
Serial Number: VMware-50 2a 97 c6 3e 64 b4 f5-ec 9f 59 78 f3 5d 13 6a
UUID: 502A97C6-3E64-B4F5-EC9F-5978F35D136A
Wake-up Type: Power Switch
Handle 0x0002
DMI type 2, 15 bytes.
Base Board Information
Manufacturer: Intel Corporation
Product Name: 440BX Desktop Reference Platform
Version: None
Serial Number: None
Asset Tag: Not Specified
Features: None
Location In Chassis: Not Specified
Chassis Handle: 0x0000
Type: Unknown
Contained Object Handlers: 0
Handle 0x0003
DMI type 3, 21 bytes.
Chassis Information
Manufacturer: No Enclosure
Type: Other
Lock: Not Present
Version: N/A
Serial Number: None
Asset Tag: No Asset Tag
Boot-up State: Safe
Power Supply State: Safe
Thermal State: Safe
Security Status: None
OEM Information: 0x00001234
Heigth: Unspecified
Number Of Power Cords: Unspecified
Contained Elements: 0
awk -v S="System Information" '
{
if ( $0 !~ /^ / )
T = $0
if ( T )
A[T] = A[T] ? A[T] RS $0 : $0
}
END {
for ( k in A )
{
if ( A[k] ~ S )
print A[k]
} }
' file.txt
@Yoda - Sorry your solution NOT working. It just prints System Information
# awk -v S="System Information" '
{
if ( $0 !~ /^ / )
T = $0
if ( T )
A[T] = A[T] ? A[T] RS $0 : $0
}
END {
for ( k in A )
{
if ( A[k] ~ S )
print A[k]
} }
' /tmp/dmi_out
System Information
@Scrutinzer - You are right. Actually I need to run dmidecode -t system which does NOT work on older RHEL 3 & 4 [ It works on RHEL 5.3 onwards ]. Hence Am trying to run just dmidecode and extract only the paragraph with "System Information".