Julian Parker
asked on
processing dmidecode using awk
Hi All,
I really dont use awk half as much as I used to and when I did I never really got to grips with anything apart from the simple stuff....
I have the following dmidecode output;
I want to extract the following information for each memory bank;
Size:
Form Factor:
Locator:
Type:
Type Detail:
Speed:
Manufacturer:
Serial Number:
Asset Tag:
Part Number:
...and I will need the output in csv format...
I will assume that all sizes are in MB and if a memory slot is not populated it uses 0 as the size.
I'm after an answer fairly quick and dont have the time to google or play about myself.
I really dont use awk half as much as I used to and when I did I never really got to grips with anything apart from the simple stuff....
I have the following dmidecode output;
Handle 0x003E, DMI type 17, 28 bytes
Memory Device
Array Handle: 0x003C
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 2048 MB
Form Factor: DIMM
Set: 1
Locator: XMM1
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous
Speed: 1333 MHz
Manufacturer: JEDEC ID:80 AD
Serial Number: 8106812F
Asset Tag: Not Specified
Part Number: HMT125U6BFR8C-H9
Rank: 2
Handle 0x003F, DMI type 17, 28 bytes
Memory Device
Array Handle: 0x003C
Error Information Handle: Not Provided
Total Width: Unknown
Data Width: Unknown
Size: No Module Installed
Form Factor: DIMM
Set: 1
Locator: XMM2
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous
Speed: Unknown
Manufacturer: JEDEC ID:
Serial Number:
Asset Tag: Not Specified
Part Number:
Rank: Unknown
Handle 0x0040, DMI type 17, 28 bytes
Memory Device
Array Handle: 0x003C
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 2048 MB
Form Factor: DIMM
Set: 2
Locator: XMM3
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous
Speed: 1333 MHz
Manufacturer: JEDEC ID:80 AD
Serial Number: 7006C12F
Asset Tag: Not Specified
Part Number: HMT125U6BFR8C-H9
Rank: 2
Handle 0x0041, DMI type 17, 28 bytes
Memory Device
Array Handle: 0x003C
Error Information Handle: Not Provided
Total Width: Unknown
Data Width: Unknown
Size: No Module Installed
Form Factor: DIMM
Set: 2
Locator: XMM4
Bank Locator: Not Specified
Type: DDR3
Type Detail: Synchronous
Speed: Unknown
Manufacturer: JEDEC ID:
Serial Number:
Asset Tag: Not Specified
Part Number:
Rank: Unknown
Handle 0x0043, DMI type 17, 28 bytes
Memory Device
Array Handle: 0x003D
Error Information Handle: Not Provided
Total Width: 2 bits
Data Width: 2 bits
Size: 4096 kB
Form Factor: Chip
Set: None
Locator: SYSTEM ROM
Bank Locator: Not Specified
Type: Flash
Type Detail: Non-Volatile
Speed: Unknown
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Rank: Unknown
I want to extract the following information for each memory bank;
Size:
Form Factor:
Locator:
Type:
Type Detail:
Speed:
Manufacturer:
Serial Number:
Asset Tag:
Part Number:
...and I will need the output in csv format...
2048,DIMM,XMM3,DDR3,Synchronous,1333 MHz,JEDEC ID:80 AD,7006C12F,Not Specified,HMT125U6BFR8C-H9
0,DIMM,XMM4,DDR3,Synchronous,Unknown,JEDEC ID:,Not Installed,Not Specified,Not Installed
I will assume that all sizes are in MB and if a memory slot is not populated it uses 0 as the size.
I'm after an answer fairly quick and dont have the time to google or play about myself.
awk -F: '/Size|Form Factor|Locator|Type|Type Detail|Speed|Manufacturer| Serial Number|Asset Tag|Part Number/{s=sprintf("%s,%s", s,$2)}/^Me mory/{prin t s;s=""}END{print s}' yourfile
ASKER
Thanks ahoffmann, that gives me the following output;
, 2048 MB, DIMM, XMM1, Not Specified, DDR3, Synchronous, 1333 MHz, JEDEC ID, 7306912F, Not Specified, HMT125U6BFR8C-H9
, No Module Installed, DIMM, XMM2, Not Specified, DDR3, Synchronous, Unknown, JEDEC ID, , Not Specified,
, 2048 MB, DIMM, XMM3, Not Specified, DDR3, Synchronous, 1333 MHz, JEDEC ID, 8106612F, Not Specified, HMT125U6BFR8C-H9
, No Module Installed, DIMM, XMM4, Not Specified, DDR3, Synchronous, Unknown, JEDEC ID, , Not Specified,
Any way of tidying it up? Can you get rid of the first comma and I just need a numeric in the 1st field so if this isnt right can it be changed to "0" and the manufacturer is delimited with a `:` so the reference is missed off.
Also, I've just found that in some cases the Locator has comma chars in it which will knacker up the csv so it might need to be put into quotes like;
"2048","DIMM","XMM1","Not Specified","DDR3","Synchro nous","133 3 MHz","JEDEC ID:70","7306912F","Not Specified","HMT125U6BFR8C- H9"
Just trying to save time with the post processing :-)
thanks
, 2048 MB, DIMM, XMM1, Not Specified, DDR3, Synchronous, 1333 MHz, JEDEC ID, 7306912F, Not Specified, HMT125U6BFR8C-H9
, No Module Installed, DIMM, XMM2, Not Specified, DDR3, Synchronous, Unknown, JEDEC ID, , Not Specified,
, 2048 MB, DIMM, XMM3, Not Specified, DDR3, Synchronous, 1333 MHz, JEDEC ID, 8106612F, Not Specified, HMT125U6BFR8C-H9
, No Module Installed, DIMM, XMM4, Not Specified, DDR3, Synchronous, Unknown, JEDEC ID, , Not Specified,
Any way of tidying it up? Can you get rid of the first comma and I just need a numeric in the 1st field so if this isnt right can it be changed to "0" and the manufacturer is delimited with a `:` so the reference is missed off.
Also, I've just found that in some cases the Locator has comma chars in it which will knacker up the csv so it might need to be put into quotes like;
"2048","DIMM","XMM1","Not Specified","DDR3","Synchro
Just trying to save time with the post processing :-)
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect...yet again!!
Now that it's a csv file I can post process easy enough.
Cheers
Jools
Now that it's a csv file I can post process easy enough.
Cheers
Jools