?
Solved

processing multiple fields in a stanza using awk

Posted on 2008-06-17
2
Medium Priority
?
762 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 1000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

770 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