another parsing question

Input File

 
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

 
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 ....

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

 
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:
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=$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

1 Like

Ahamad ,

it works fine except in the following case

 
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