File Parsing

(imported topic written by jeko1791)

I know I’m close. Can someone help me over the hump here.

I’m trying the parse the following txt output from a Linux command “dmidecode”:

SMBIOS 2.31 present.\par

45 structures occupying 1701 bytes.\par

Table at 0x000E0010.\par

Handle 0x0000\par

\tab DMI type 0, 20 bytes.\par

\tab BIOS Information\par

\tab\tab Vendor: Phoenix Technologies LTD\par

\tab\tab Version: 6.00\par

\tab\tab Release Date: 02/01/2008\par

\tab\tab Address: 0xE7C40\par

\tab\tab Runtime Size: 99264 bytes\par

\tab\tab ROM Size: 64 kB\par

\tab\tab Characteristics:\par

\tab\tab\tab ISA is supported\par

\tab\tab\tab PCI is supported\par

\tab\tab\tab PC Card (PCMCIA) is supported\par

\tab\tab\tab PNP is supported\par

\tab\tab\tab APM is supported\par

\tab\tab\tab BIOS is upgradeable\par

\tab\tab\tab BIOS shadowing is allowed\par

\tab\tab\tab ESCD support is available\par

\tab\tab\tab USB legacy is supported\par

\tab\tab\tab Smart battery is supported\par

\tab\tab\tab BIOS boot specification is supported\par

Handle 0x0001\par

\tab DMI type 1, 25 bytes.\par

\tab System Information\par

\tab\tab Manufacturer: VMware, Inc.\par

\tab\tab Product Name: VMware Virtual Platform\par

\tab\tab Version: None\par

\tab\tab Serial Number: VMware-50 0d fb 98 a6 89 18 31-0e 58 e8 e7 bf ae 02 37\par

\tab\tab UUID: 500DFB98-A689-1831-0E58-E8E7BFAE0237\par

\tab\tab Wake-up Type: Power Switch\par

Handle 0x0002\par

\tab DMI type 2, 8 bytes.\par

\tab Base Board Information\par

\tab\tab Manufacturer: Intel Corporation\par

\tab\tab Product Name: 440BX Desktop Reference Platform\par

\tab\tab Version: None\par

\tab\tab Serial Number: None\par

Handle 0x0003\par

I want the value following “Manufacturer:” under the Handle 0x0001 section (not really a section by inspector standards). Hre’s what I’ve got so far:

q: preceding texts of first “” of following texts of first “Manufacturer:” of lines of file “d:\dmi.txt”

A: VMware, Inc.

E: Singular expression refers to non-unique object.

I would like to add of following text of first “Handle 0x0001” so there will never be any confusion over which “Manufacturer:” I’m looking for, but not sure where to add that. Also, not sure how to make this a unique response.

(imported comment written by BenKus)

Hey Jeff,

If you add some ‘s’ after your ‘first’:

q: preceding texts of firsts “” of following texts of firsts “Manufacturer:” of lines of file "c:\temp\test.txt"
A: VMware, Inc.
A: Intel Corporation

If you want only the first one of these, then you will need to concatenate the results first:

q: (preceding texts of firsts “” of following texts of firsts “Manufacturer:” of concatenation of lines of file “c:\temp\test.txt”) as trimmed string
A: VMware, Inc.

Ben

(imported comment written by SystemAdmin)

DMIDecode has different sections… , so the above code grabs all of them

the biggect problem with the above code is grabbing serial numbers, there could be 8+ “Serial Number:”

in the entire dmidecode output, i would only want the “Handle 0x0100” or “DMI type 1” Serial Number:

so something like the first “Manufacturer:” after “Handle 0x0100”

or the first “Manufacturer:” after “Handle 0x0300”

Handle 0x0100

DMI type 1, 25 bytes.

System Information

Manufacturer: HP

Product Name: ProLiant BL460c G6

Handle 0x0300

DMI type 3, 17 bytes.

Chassis Information

Manufacturer: HP

Type: Rack Mount Chassis

Handle 0x0400

DMI type 4, 40 bytes.

Processor Information

Socket Designation: Proc 1

Type: Central Processor

Family: Xeon

Manufacturer: Intel

(imported comment written by BenKus)

This should work if the file is not too big:

preceding texts of firsts “” of following text of firsts "Manufacturer: " of following text of firsts “Handle 0x0000” of concatenation of lines of file “C:\temp\test.txt”

Ben

(imported comment written by SystemAdmin)

Ben Kus

This should work if the file is not too big:
preceding texts of firsts “” of following text of firsts "Manufacturer: " of following text of firsts “Handle 0x0000” of concatenation of lines of file “C:\temp\test.txt”

Ben

I added some error checking and changed the “” to “%09” … works great…

Thank you

if exists “/etc/dmidecode.txt” then (preceding texts of firsts “%09” of following text of firsts “Manufacturer:” of following text of firsts “Handle 0x0100” of concatenation of lines of file “/etc/dmidecode.txt”) as trimmed string else “”

if exists “/etc/dmidecode.txt” then (preceding texts of firsts “%09” of following text of firsts “Manufacturer:” of following text of firsts “Handle 0x0300” of concatenation of lines of file “/etc/dmidecode.txt”) as trimmed string else “”

(imported comment written by SystemAdmin)

FYI:

Here’s an update to gathering the DMIDecode information,

after running the task

#!/bin/sh /usr/sbin/dmidecode >/root/dmidecode.out

I gather the information with this Analysis

System Info (Manufacturer)   

if exists 
"/root/dmidecode.out" then (preceding texts of firsts 
"%09" of following text of firsts 
"Manufacturer:" of following text of firsts 
"DMI type 1," of concatenation of lines of file 
"/root/dmidecode.out") as trimmed string 

else 
"<No Information>"     System Info (Serial Number)   

if exists 
"/root/dmidecode.out" then (preceding texts of firsts 
"%09" of following text of firsts 
"Serial Number:" of following text of firsts 
"DMI type 1," of concatenation of lines of file 
"/root/dmidecode.out") as trimmed string 

else 
"<No Information>"     System Info (Product Name)   

if exists 
"/root/dmidecode.out" then (preceding texts of firsts 
"%09" of following text of firsts 
"Product Name:" of following text of firsts 
"DMI type 1," of concatenation of lines of file 
"/root/dmidecode.out") as trimmed string 

else 
"<No Information>"     Chassis Info (Manufacturer)   

if exists 
"/root/dmidecode.out" then (preceding texts of firsts 
"%09" of following text of firsts 
"Manufacturer:" of following text of firsts 
"DMI type 3," of concatenation of lines of file 
"/root/dmidecode.out") as trimmed string 

else 
"<No Information>"     Chassis Info (Type)   

if exists 
"/root/dmidecode.out" then (preceding texts of firsts 
"%09" of following text of firsts 
"Type:" of following text of firsts 
"DMI type 3," of concatenation of lines of file 
"/root/dmidecode.out") as trimmed string 

else 
"<No Information>"     Chassis Info (Serial Number)   

if exists 
"/root/dmidecode.out" then (preceding texts of firsts 
"%09" of following text of firsts 
"Serial Number:" of following text of firsts 
"DMI type 3," of concatenation of lines of file 
"/root/dmidecode.out") as trimmed string 

else 
"<No Information>"Relevance     Relevance 1   (name of operating system as lowercase contains 
"linux") or (name of operating system as lowercase contains 
"esx")