another parsing question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting another parsing question
# 1  
Old 01-06-2012
another parsing question

Input File

Code:
 
Information about each HBA:
HBA UID:                 20:00:00:00:C9:9A:62:88:10:00:00:00:C9:9A:62:88
Server Name:             20:00:00:00:C9:9A:62:88:10:00:00:00:C9:9A:62:88
Server IP Address:       UNKNOWN
HBA Model Description:
HBA Vendor Description:
HBA Device Driver Name:
Information about each port of this HBA:
    SP Name:               SP B
    SP Port ID:            0
    HBA Devicename:
    Trusted:               NO
    Logged In:             YES
    Source ID:             332800
    Defined:               NO
    Initiator Type:           3
    StorageGroup Name:     None
 
    SP Name:               SP A
    SP Port ID:            1
    HBA Devicename:
    Trusted:               NO
    Logged In:             YES
    Source ID:             332800
    Defined:               NO
    Initiator Type:           3
    StorageGroup Name:     None
 
Information about each HBA:
HBA UID:                 20:00:00:00:C9:9A:5F:72:10:00:00:00:C9:9A:5F:72
Server Name:             joshua
Server IP Address:       172.28.48.25
HBA Model Description:
HBA Vendor Description:
HBA Device Driver Name:
Information about each port of this HBA:
    SP Name:               SP B
    SP Port ID:            1
    HBA Devicename:        PwrP:c2t500601693B203C15d0s0
    Trusted:               NO
    Logged In:             YES
    Defined:               YES
    Initiator Type:           3
    StorageGroup Name:     joshua
 
    SP Name:               SP A
    SP Port ID:            0
    HBA Devicename:        PwrP:c2t500601603B203C15d0s0
    Trusted:               NO
    Logged In:             YES
    Defined:               YES
    Initiator Type:           3
    StorageGroup Name:     joshua


Output needed

Code:
 
Server Name,HBA UID,SP Name:SP Port ID,Logged in ,Defined,StorageGroup Name
20:00:00:00:C9:9A:62:88:10:00:00:00:C9:9A:62:88,20:00:00:00:C9:9A:62:88:10:00:00:00:C9:9A:62:88,SPB:0-SPA:1,YES,NO,None
joshua,20:00:00:00:C9:9A:5F:72:10:00:00:00:C9:9A:5F:72,SPB:1-SPA:0,YES,YES,joshua

Please note that SP Name and SP Port ID appears twice in one record and i want to combine them like this
SP Name:SP PortID-SP Name:SP PortID

Thanks

---------- Post updated at 09:56 AM ---------- Previous update was at 04:12 AM ----------

I tried something like this ... this works for 1st record , but not for 2nd as the record lenght is diff ....

Code:
nawk  'BEGIN{ RS="\n"}
/^HBA UID:/ { hbaa=$3}
/Server Name:/ { name=$3}
/SP Name:/ { spa1=$3$4 }
/SP Port ID:/ { port1=$4 ;getline ;getline;getline ;logg=$3;getline;getline ;deff=$2;getline ;getline;getline ;spa2=$3$4;getline;por
t2=$4
printf "%s\n",name","hbaa","spa1":"port1"-"spa2":"port2","logg","deff > "/tmp/c-out"
                FS=" "
}' /tmp/input

Output

Code:
 
20:00:00:00:C9:9A:62:88:10:00:00:00:C9:9A:62:88,20:00:00:00:C9:9A:62:88:10:00:00:00:C9:9A:62:88,SPB:0-SPA:1,YES,NO
joshua,20:00:00:00:C9:9A:5F:72:10:00:00:00:C9:9A:5F:72,SPB:1-ID:0:,YES,Type:


Last edited by zxmaus; 01-07-2012 at 10:49 AM.. Reason: added tags
# 2  
Old 01-07-2012
Code:
awk 'BEGIN{print "Server Name, HBA UID, SP Name:SP Port ID, Logged In, Defined, StorageGroup Name"}
/Server Name/{a=$NF} /HBA UID/{b=$NF} /SP Name/{c[++i]=$(NF-1)$NF}
/SP Port ID/{d[i]=$NF} /Logged In/{e=$NF} /Defined/{f=$NF}
/StorageGroup Name/{g=$NF;p++} p==2{print a,b,c[1]":"d[1]"-"c[2]":"d[2],e,f,g;i=p=0;}' OFS=, infile

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 3  
Old 01-09-2012
Ahamad ,

it works fine except in the following case

Code:
 
Information about each HBA:
HBA UID:                 20:00:00:00:C9:63:C2:CC:10:00:00:00:C9:63:C2:CC
Server Name:             starport
Server IP Address:       172.31.128.50
HBA Model Description:
HBA Vendor Description:
HBA Device Driver Name:
Information about each port of this HBA:
    SP Name:               SP A
    SP Port ID:            0
    HBA Devicename:        c2t500601603CA01347d0s0
    Trusted:               NO
    Logged In:             YES
    Source ID:             161792
    Defined:               YES
    Initiator Type:           3
    StorageGroup Name:     None
 
Information about each HBA:
HBA UID:                 20:00:00:00:C9:9A:5F:72:10:00:00:00:C9:9A:5F:72
Server Name:             joshua
Server IP Address:       172.28.48.25
HBA Model Description:
HBA Vendor Description:
HBA Device Driver Name:
Information about each port of this HBA:
    SP Name:               SP B
    SP Port ID:            1
    HBA Devicename:        PwrP:c2t500601693B203C15d0s0
    Trusted:               NO
    Logged In:             YES
    Defined:               YES
    Initiator Type:           3
    StorageGroup Name:     joshua
 
    SP Name:               SP A
    SP Port ID:            0
    HBA Devicename:        PwrP:c2t500601603B203C15d0s0
    Trusted:               NO
    Logged In:             YES
    Defined:               YES
    Initiator Type:           3
    StorageGroup Name:     joshua

In this case the 1st record does not show up as there is no repeating fields ...

thx
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Another parsing question (awk)

Input File Name of the session: filesrv_quo snap Logical Units UID: 60:06:01:60:01:7B:25:00:C8:86:B0:CA:5B:A2:E0:11 Name of the session: verspn2_at_176_0218 snap Logical Units UID: Name of the session: DRT-ny-iadsql1-c_ny-iadsql2-c snap Logical Units UID: ... (4 Replies)
Discussion started by: greycells
4 Replies

2. UNIX for Dummies Questions & Answers

Noob question about parsing a website

I'm trying to parse the website, finance.yahoo.com/q?s=ge&ql=1, and retrieve the info between <span id="yfs_l84_ge">18.98</span>, so 18.98. What would be the best way to go about this in a bash script? Any help or suggestions will be much appreciated. Thanks! (2 Replies)
Discussion started by: mayson
2 Replies

3. Shell Programming and Scripting

Question about argument parsing in scripts

Hello all, I am relatively new to linux and bash scripting. I have what seems to be a simple question but I'm having trouble finding the answer. The question is what is the difference between the variables $@ and $*. I've seen them both used in the same context, and I've tried a number of... (4 Replies)
Discussion started by: nicthu
4 Replies

4. Shell Programming and Scripting

Question about reading and parsing text file

Hello, I'm just getting started with BASH programming. I would like to write a script to solve a file renaming problem I have. I received a directory containing a collection (>2000) of files whose names are in DOS 8.3 format, and woild like to rename the filenames to a longer and more... (8 Replies)
Discussion started by: polomora
8 Replies

5. Shell Programming and Scripting

Perl parsing question

I need some help loading an array. I have two unique delimiters, but I keep running into recursion. #!/usr/bin/perl $INFILE="/root/scripts/data.txt"; $pat1="SCRIPT####"; $pat2="SCRIPT#echo"; $flag=0; $inc=0; $chunk=""; open(INFILE,"<$INFILE")|| die; while(<INFILE>) { if... (2 Replies)
Discussion started by: s_becker
2 Replies

6. Shell Programming and Scripting

Question about Awk for Data Parsing

Hi, I am doing some data parsing for some economics research. I was recently exposed to shell script and am brand new to awk. I have a large csv file (like 10G) and I would like to make it a lot smaller with awk, but it is a bit tricky for me and I haven't been able to get it yet. I would... (5 Replies)
Discussion started by: EconResearch
5 Replies

7. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

8. Shell Programming and Scripting

Parsing question.

Hi There, First time poster here. I've got a parsing question and have a solution but am sure there is a much better way of doing this with just awk. My knowledge of awk is pretty limited so hope someone out there can give me a better solution. Here's the problem, I'm receiving a file from a... (2 Replies)
Discussion started by: little_happosai
2 Replies

9. Shell Programming and Scripting

Parsing question

Hi Guys, I was wondering if you could help me out - I have a directory /home/users/datafiles/ which contain files "dat dd-mm-yy.xls" I am trying to write a script which does the following - (1) loops through all the files (2) retrieves the dd-mm-yy string and converts it into a... (12 Replies)
Discussion started by: muser
12 Replies

10. UNIX for Dummies Questions & Answers

Text parsing question

How would I split a file based on the location of a string, basically I want all entries above the string unix in this example 1 2 3 4 unix 5 6 7 Thanks, Chuck (3 Replies)
Discussion started by: 98_1LE
3 Replies
Login or Register to Ask a Question