LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-16-2012, 06:01 AM   #1
em31amit
Member
 
Registered: Apr 2012
Location: /root
Distribution: Ubuntu, Redhat, Fedora, CentOS
Posts: 190

Rep: Reputation: 55
reporting with AWK script ?? pattern search multiple


I have this output which is i am getting with "dmidecode" command

Code:
Handle 0x110F, DMI type 17, 34 bytes
Memory Device
	Array Handle: 0x1001
	Error Information Handle: Not Provided
	Total Width: 72 bits
	Data Width: 64 bits
	Size: No Module Installed
	Form Factor: DIMM
	Set: 16
	Locator: PROC 2 DIMM 7I
	Bank Locator: Not Specified
	Type: DDR3
	Type Detail: Synchronous
	Speed: Unknown
	Manufacturer: Not Specified
	Serial Number: Not Specified
	Asset Tag: Not Specified
	Part Number: Not Specified
	Rank: Unknown

Handle 0x1110, DMI type 17, 34 bytes
Memory Device
	Array Handle: 0x1001
	Error Information Handle: Not Provided
	Total Width: 72 bits
	Data Width: 64 bits
	Size: 4096 MB
	Form Factor: DIMM
	Set: 17
	Locator: PROC 2 DIMM 8F
	Bank Locator: Not Specified
	Type: DDR3
	Type Detail: Synchronous
	Speed: 1333 MHz
	Manufacturer: Not Specified
	Serial Number: Not Specified
	Asset Tag: Not Specified
	Part Number: Not Specified
	Rank: 1

Handle 0x1111, DMI type 17, 34 bytes
Memory Device
	Array Handle: 0x1001
	Error Information Handle: Not Provided
	Total Width: 72 bits
	Data Width: 64 bits
	Size: 8192 MB
	Form Factor: DIMM
	Set: 18
	Locator: PROC 2 DIMM 9C
	Bank Locator: Not Specified
	Type: DDR3
	Type Detail: Synchronous
	Speed: 1333 MHz
	Manufacturer: Not Specified
	Serial Number: Not Specified
	Asset Tag: Not Specified
	Part Number: Not Specified
	Rank: 2
I need to two line from this output i.e
1) Locator: PROC 2 DIMM 9C
2) Size: 8192 MB


And i want to format or report something like this.
Code:
 DIMMS               SIZE
============================
PROC 2 DIMM 9C       8192 MB

.....

I tried it with awk, but no luck.

Code:
dmidecode -t Memory |  egrep "PROC|SIZE" | awk '
/PROC/ { sub(/^.*: /,"");MEM = $0 }
/SIZE/ { sub(/^.*: /,"");SI = $0 }
/^$/ { if ( MEM ) print MEM, "\t" $0 }
'
can someone guide me, i checked for this awk on somewhere on another forum, as mentioned that it was working for them good than i modified it for my need.
http://www.linuxmisc.com/12-unix-she...fb1e5b4abb.htm


But no luck. I am Newbie in awk and i am using GNU Awk 3.1.5
 
Old 06-16-2012, 08:28 AM   #2
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
So wassa problem? Whats not lucky Amit?

Is the egrep failing or the awk or do you want to sort the output in descending order of size?

Can you show us the intermediate results, wrong output, error message?

OK
 
Old 06-16-2012, 08:38 AM   #3
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.

Save the following script to some file, say, `getinfo.awk', and run
Code:
dmidecode -t Memory | awk -f getinfo.awk
Code:
BEGIN{  print " DIMMS\t\tSIZE";
	for(i=0; i<30; i++) printf "=";
	print
	}
/PROC/ { sub(/^.*: /,"");MEM = $0 }
/Size/ { sub(/^.*: /,"");SI = $0 }
/^$/ { if ( MEM ) print MEM, "\t", SI }
 
1 members found this post helpful.
Old 06-16-2012, 11:28 AM   #4
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
How about
Code:
sudo dmidecode -t Memory | awk '/^[\t ]/ {
    key = tolower($0) ; sub(/^[\t ]*/, "", key) ; sub(/:.*$/, "", key) ; gsub(/[^0-9a-z]+/, "", key) ;
    val = $0 ; sub(/^[^:]*:[\t ]*/, "", val) ; list[key] = val ;
    next
}
{   if (("size" in list) && ("locator" in list))
        printf("%s\t%s\t%s\t%s %s %s %s\t%s\n", list["locator"], list["banklocator"], list["size"], list["typedetail"], list["type"], list["formfactor"], list["speed"], list["serialnumber"]) ;
    split("", list) }'
You can put it all on one long line; I added the semicolons for just that case. On my system, this outputs
Code:
DIMM0	BANK0	1024 MB	Synchronous DDR2 DIMM 400 MHz (2.5 ns)	SerNum0
DIMM1	BANK1	1024 MB	Synchronous DDR2 DIMM 400 MHz (2.5 ns)	SerNum1
DIMM2	BANK2	2048 MB	Synchronous DDR2 DIMM 400 MHz (2.5 ns)	SerNum2
DIMM3	BANK3	2048 MB	Synchronous DDR2 DIMM 400 MHz (2.5 ns)	SerNum3
 
1 members found this post helpful.
Old 06-17-2012, 04:55 AM   #5
em31amit
Member
 
Registered: Apr 2012
Location: /root
Distribution: Ubuntu, Redhat, Fedora, CentOS
Posts: 190

Original Poster
Rep: Reputation: 55
Thanks firstfire and Nominal Animal,

It works, My problem Solved.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] search, duplicate and add pattern with sed/awk lolworlds Programming 4 02-03-2012 10:17 AM
How to search a pattern only first line using awk debianD Programming 8 08-02-2011 08:19 PM
How to use variables in search pattern in gensub function of awk rajeshksv Linux - Newbie 1 08-07-2009 07:07 AM
multiple pattern search and count the no. of occurances raghu123 Programming 4 06-03-2009 04:50 PM
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 05:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration