Solved

processing multiple fields in a stanza using awk

Posted on 2008-06-17
2
735 Views
Last Modified: 2011-08-18
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
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

}'

Open in new window

0
Comment
Question by:jools
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 21801027
awk '/Socket Designation:/{printf"%-20s",$3}/Installed Size:/{print $3,$4}' < hardware
0
 
LVL 19

Author Comment

by:jools
ID: 21801350
Thanks ozo,

Glad to see you're still about.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now