Julian Parker
asked on
processing multiple fields in a stanza using awk
Hi,
I've been trying to use awk to process a stanza with the following information;
Handle 0x000D, DMI type 6, 12 bytes.
Memory Module Information
Socket Designation: DIMM0
Bank Connections: 0 5
Current Speed: 160 ns
Type: DIMM
Installed Size: 512 MB (Double-bank Connection)
Enabled Size: 512 MB (Double-bank Connection)
Error Status: OK
Handle 0x000E, DMI type 6, 12 bytes.
Memory Module Information
Socket Designation: DIMM1
Bank Connections: 0 5
Current Speed: 162 ns
Type: DIMM
Installed Size: 512 MB (Double-bank Connection)
Enabled Size: 512 MB (Double-bank Connection)
Error Status: OK
I would like to extract the Socket Designation and Installed Size fields to summarise the installed memory and look something like this;
DIMM0 512 MB
DIMM1 512 MB
I have attached a code snippet from one of my many failed attempts below.
Is awk the best thing to use for this or would perl be more suited (in which case I won't know where to start!)
Any help greatly apprecisted.
Jools
I've been trying to use awk to process a stanza with the following information;
Handle 0x000D, DMI type 6, 12 bytes.
Memory Module Information
Socket Designation: DIMM0
Bank Connections: 0 5
Current Speed: 160 ns
Type: DIMM
Installed Size: 512 MB (Double-bank Connection)
Enabled Size: 512 MB (Double-bank Connection)
Error Status: OK
Handle 0x000E, DMI type 6, 12 bytes.
Memory Module Information
Socket Designation: DIMM1
Bank Connections: 0 5
Current Speed: 162 ns
Type: DIMM
Installed Size: 512 MB (Double-bank Connection)
Enabled Size: 512 MB (Double-bank Connection)
Error Status: OK
I would like to extract the Socket Designation and Installed Size fields to summarise the installed memory and look something like this;
DIMM0 512 MB
DIMM1 512 MB
I have attached a code snippet from one of my many failed attempts below.
Is awk the best thing to use for this or would perl be more suited (in which case I won't know where to start!)
Any help greatly apprecisted.
Jools
cat hardware | awk -F: '
BEGIN {
RS = "^Memory Module Information"
}
/Socket Designation/ { SDES = $2 }
/Installed Size/ { ISIZE = $2 }
END {
printf "%-20s %-20s\n",SDES,ISIZE
print NR
}'
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Glad to see you're still about.