Hi rbatte1 thank you for your reply.
No this is not homework. I use awk/sed/grep scripts on occasion and at times I get caught in a rut when more complex scripting is required. For this particular thread I have been tasked with having to pull relevent info from a file is produced daily from our SAN storage enviroment. My background is unix, I use shell scripts more than anything else to filter out information when needs be.
This is a sample of the original file.
/clusters/cluster-1/exports/storage-views/NETIK0102_Boot:
Name Value
------------------------ -----------------------------------------------------------------------------
caw-enabled true
controller-tag -
initiators [NETIK0102_UCS_Boot_a, NETIK0102_UCS_Boot_b]
operational-status ok
port-name-enabled-status [P00000000476043B3-A0-FC01,true,ok, P00000000476046CC-A0-FC00,true,ok,
P00000000477043B3-B0-FC00,true,ok, P00000000477046CC-B0-FC01,true,ok]
ports [P00000000476043B3-A0-FC01, P00000000476046CC-A0-FC00,
P00000000477043B3-B0-FC00, P00000000477046CC-B0-FC01]
virtual-volumes [(0,device_Symm5200_2438_1_vol,VPD83T3:60001440000000106046cc5f567eb9b9,70G),
(1,device_Symm5200_2439_1_vol,VPD83T3:60001440000000106046cc5f567eb9bf,70G)]
write-same-16-enabled true
/clusters/cluster-1/exports/storage-views/NETIK0102_Shared:
Name Value
------------------------ -------------------------------------------------------------------------------
caw-enabled true
controller-tag -
initiators [NETIK0102_UCS_HBA0_a, NETIK0102_UCS_HBA1_b, NETIK0102_UCS_HBA2_a,
NETIK0102_UCS_HBA3_b]
operational-status ok
port-name-enabled-status [P00000000476043B8-A0-FC02,true,ok, P0000000047604458-A0-FC03,true,ok,
P00000000477043B8-B0-FC03,true,ok, P0000000047704458-B0-FC02,true,ok]
ports [P00000000476043B8-A0-FC02, P0000000047604458-A0-FC03,
P00000000477043B8-B0-FC03, P0000000047704458-B0-FC02]
virtual-volumes [(0,device_Symm2363_19D7_1_vol,VPD83T3:60001440000000106046cc5f567eb7dc,55G),
(1,device_Symm2363_19C0_1_vol,VPD83T3:60001440000000106046cc5f567eb769,30G),
(2,device_Symm2363_19F5_1_vol,VPD83T3:60001440000000106046cc5f567eb872,120G),
(3,device_Symm2363_1A03_1_vol,VPD83T3:60001440000000106046cc5f567eb8ae,280G),
(4,device_Symm2363_19DC_1_vol,VPD83T3:60001440000000106046cc5f567eb7f5,66G),
(5,device_Symm2363_1A6C_1_vol,VPD83T3:60001440000000106046cc5f567eb93f,600G),
(6,device_Symm2363_1998_1_vol,VPD83T3:60001440000000106046cc5f567eb9ad,10G),
(7,device_Symm2363_19CE_1_vol,VPD83T3:60001440000000106046cc5f567eb9b3,40G),
(8,device_Symm2363_1A7E_1_vol,VPD83T3:60001440000000106046cc5f567eb9c5,1000G),
(9,device_Symm2363_19B9_1_vol,VPD83T3:60001440000000106046cc5f567eb9cb,20G),
(10,device_Symm2363_19BA_1_vol,VPD83T3:60001440000000106046cc5f567eb9d1,20G),
(11,device_Symm2363_19BB_1_vol,VPD83T3:60001440000000106046cc5f567eb9d7,20G),
(12,device_Symm2363_19BC_1_vol,VPD83T3:60001440000000106046cc5f567eb9dd,20G),
(13,device_Symm2363_1AA3_1_vol,VPD83T3:60001440000000106046cc5f567eb9e3,2.93T),
(14,device_Symm2363_1A94_1_vol,VPD83T3:60001440000000106046cc5f567eb9e9,750G),
(15,device_Symm2363_1A88_1_vol,VPD83T3:60001440000000106046cc5f567eb9ef,300G)]
write-same-16-enabled true
From this file I have been able to use the following commands to pull out the releven information.
cat file | awk '/initiators/,/write-same-16-enabled/ {print $0}' \
| grep -v operational-status \
| grep -v P00000000 \
| grep -v write-same-16-enabled \
| grep -v '\[\]' \
| sed 's/ //g' \
| sed 's/initiators/initiators /g' \
| nawk '/a,$|b,$|A,$|B,$/ {printf "%s",substr($0, 1, length-1)",";next} 1' \
| sed 's/initiators \[//g;s/\]//g' | sed 's/virtual-volumes\[//g' \
| nawk '{if(/^\(/) {FS=","; print$2,$4 }else {print$0}}' \
| sed 's/device_Symm2363_/2673 /g' \
| sed 's/device_Symm5200_/5200 /g' \
| sed 's/_1_vol//g' \
| sed 's/)//g'
The code above is not very efficient I know but it works. I will go back to cleaning it up once I get it all working the way I want it. But for the past few days I have struggled with trying to get the last bit regarding what I posted earlier.
I thank you for your help on this.
---------- Post updated at 01:34 PM ---------- Previous update was at 01:25 PM ----------
Hi SriniShoo,
I have tried you code but I am getting the following error. I tried using awk and nawk (I am running this on a Solaris box).
nawk: you can only delete array[element] at source line 1
context is
/,/ {rcrsv(); c=split($0, a, ","); n=0; delete >>> b; <<<
nawk: syntax error at source line 1
nawk: illegal statement at source line 1