awk and searching within a block ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk and searching within a block ?
# 1  
Old 10-09-2009
awk and searching within a block ?

Hi, I wonder if anybody could help. How do i awk out (or indeed using another utility) a particular value that exists within a defined block, for example if i have a file that looks like the one below and i want to get at the "Product Serial" for the block referring to "mb.fru" (bolded and coloured below) then how would i do that ?.... there are lots of instances of the string "Product Serial" around the file but I want to get at the one for that particular blocked item.

note: the block for "mb.fru" could exist in different places with the file, so i cant used a fixed line each time

Ive been playing with using awk with a FS of \n and an RS of "" but cant seem to get it working, could anybody point me in the right direction?


Code:
FRU Device Description : Builtin FRU Device (ID 0)
 Board Product         : ASSY,SERV PROCESSOR,X4600 M2
 Board Serial          : 1762TH1-07200006xx
 Board Part Number     : 501-7640-03
 Board Extra           : 50
 Board Extra           : G4F_SP
 Product Manufacturer  : SUN MICROSYSTEMS
 Product Name          : ILOM

FRU Device Description : sp.net0.fru (ID 1)
 Product Manufacturer  : MOTOROLA
 Product Name          : FAST ETHERNET CONTROLLER
 Product Part Number   : MPC8248 FCC
 Product Serial        : 00:14:4F:79:52:xx
 Product Extra         : 01
 Product Extra         : 00:14:4F:79:52:xx

FRU Device Description : mb.fru (ID 2)
 Chassis Type          : Rack Mount Chassis
 Chassis Part Number   : 000-0000-00
 Chassis Serial        : 0226-0630LHF0Axx
 Board Product         : ASSY,MOTHERBOARD,X4600 M2
 Board Serial          : 1762TH1-07180001xx
 Board Part Number     : 501-7638-03
 Board Extra           : 50
 Board Extra           : G4F_MB
 Product Manufacturer  : SUN MICROSYSTEMS
 Product Name          : SUN FIRE X4600
 Product Part Number   : 602-3774-01
 Product Serial        : 0723AN19XX

FRU Device Description : mb.bios.fru (ID 3)
 Product Manufacturer  : AMERICAN MEGATRENDS
 Product Name          : SYSTEM BIOS
 Product Part Number   : AMIBIOS8
 Product Version       : 0ABIT043

FRU Device Description : mb.net0.fru (ID 4)
 Product Manufacturer  : INTEL
 Product Name          : DUAL PORT GIGABIT ETHERNET CONTROLLER (COPPER)
 Product Part Number   : 82546EB
 Product Serial        : 00:14:4F:78:D9:xx
 Product Extra         : 02
 Product Extra         : 00:14:4F:78:D9:xx
 Product Extra         : 00:14:4F:78:D9:xx

FRU Device Description : mb.net1.fru (ID 5)
 Product Manufacturer  : INTEL
 Product Name          : DUAL PORT GIGABIT ETHERNET CONTROLLER (COPPER)
 Product Part Number   : 82546EB
 Product Serial        : 00:14:4F:78:D9:xx
 Product Extra         : 02
 Product Extra         : 00:14:4F:78:D9:xx
 Product Extra         : 00:14:4F:78:D9:xx

# 2  
Old 10-09-2009
Code:
awk '!NF{f=0}/mb.fru/{f=1}/Product Serial/&&f{print $NF}' file

# 3  
Old 10-09-2009
Code:
awk '/FRU Device Description : mb.fru/,/Product Serial/ {
 if ( /Product Serial/ ) { 
      split($0,a,": ")
      print a[2] }
 }' "$file"

# 4  
Old 10-09-2009
wow thankyou guys thats great
# 5  
Old 10-09-2009
And another one:
(use gawk, nawk or /usr/xpg4/bin/awk on Solaris)
Code:
awk '/mb.fru/ { print $NF }' RS= infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching content of a variable using awk

so i'm running a variation of the following command a few times in my script: echo "${TOTALRunning}" | awk -F"" '/'"${PROCSEARCH}"'/ {print $2}' | tr '\n' '|' unfortunately i cant paste the content of the variable TOTALRunning into this thread for security reasons. what i want to do is... (9 Replies)
Discussion started by: SkySmart
9 Replies

2. Shell Programming and Scripting

Searching value in table through awk

I need to create one script in which I want to search in txt file , this txt file is having 10 columns , I want to check 4th column value if "BOY" & 10th column value =>500 it will print 4th column row value ,1st column row value & 10th column row value & store the same value in one file as... (2 Replies)
Discussion started by: dravi_laxmi
2 Replies

3. Shell Programming and Scripting

Searching multiple patterns using awk

Hello, I have the following input file: qh1adm 20130710111201 : tp import all QH1 u6 -Dsourcesystems=BFI,EBJ qh1adm 20130711151154 : tp import all QH1 u6 -Dsourcesystems=BFI,EBJ qx1adm 20130711151154 : tp count QX1 u6 -Dsourcesystems=B17,E17,EE7 qh1adm 20130711151155 : tp import all... (7 Replies)
Discussion started by: kcboy
7 Replies

4. Shell Programming and Scripting

awk: searching for non-breaking-space

This code shal search for the non-breaking space 0xA0 though it returns the error "fatal: attempt to use scalar 'nbs' as array" Can somebody help? awk --non-decimal-data -v nbs="0xA0" '{if($0 in nbs) {print FILENAME, NR}}' *.txt (1 Reply)
Discussion started by: sdf
1 Replies

5. Shell Programming and Scripting

Searching a file using awk or sed

I want to search a file in a specific location and I don't want to use find command. I want to give the path also where the file is for searching it. Pls help (3 Replies)
Discussion started by: maitree
3 Replies

6. Shell Programming and Scripting

Searching for a particular string and modifying text within block of data

Hi Forum. Is there a quick way to do the following search/replace within a block of data? I tried to google the solution but didn't really know what to look for. I have the following text file (I want to search for a particular string "s_m_f_acct_txn_daily_a1" and replace the... (5 Replies)
Discussion started by: pchang
5 Replies

7. Shell Programming and Scripting

awk searching

hi all, Please can you help me with the awk searching where: I have a master file where I need the string $12. the string $ 12 varies between 3 and 4 characters and I need to bring only the characters ending in 68. try this, but is so bad my search i know awk-F, '(if... (8 Replies)
Discussion started by: manzi
8 Replies

8. Shell Programming and Scripting

Searching using awk - Help required

Hi... I am working on script to search some records in a file based on certain fields and each record is a ASCII fixed size. I was using awk to search based on certain condition. But the length of the record is too much that awk is giving syntax error near unexpected token `(' Request... (5 Replies)
Discussion started by: ysrikanth
5 Replies

9. Shell Programming and Scripting

Searching word in a file with awk

Hello everyone! I use a script to query for installed packages with yum (I use RHEL 4 with yum installed) and the output is redirected to a file. My script scan this file to find a package and the version of it. The script works fine until I search for a package name with special characters.... (3 Replies)
Discussion started by: studieu
3 Replies

10. Shell Programming and Scripting

awk searching between two files

hi there, im writing some script in awk; in few words i have a list from router (mac address- ip address) and the second list with only the mac addresses. the thing is that i want search list from router for the first mac address; if found - print the ip address, if not print error; then search... (1 Reply)
Discussion started by: mac7
1 Replies
Login or Register to Ask a Question