Well, as I have mentioned in my original post. Each LUN (emcpower...) can have multiple disk names. So your red marked numbers are count of those disks. In my example emcpower28a has 2 disks so I mentioned number 2 there. Thats what I want to calculate. You understand what I mean?
No, I want to count number of disks associated with each emcpower. As in my example 1 LUN has 2 disks associated and another has 4. This is what I want to calculate.
---------- Post updated at 08:30 AM ---------- Previous update was at 08:29 AM ----------
Pseudo name=emcpower0a
3076 pci@2,600000/SUNW,emlxs@0/fp@0,0 c1t5Fd94s0 FA 13cA active alive 0 0
3075 pci@12,600000/SUNW,emlxs@0/fp@0,0 c3t5Dd94s0 FA 4cA active alive 0 0
Pseudo name=emcpower8a
3076 pci@2,600000/SUNW,emlxs@0/fp@0,0 c1t5Cd95s0 FA 13cA active alive 0 0
3075 pci@12,600000/SUNW,emlxs@0/fp@0,0 c3t53d95s0 FA 4cA active alive 0 0
3073 pci@12,600000/SUNW,emlxs@0/fp@0,0 c3t54d95s0 FA 4cA active alive 0 0
Pseudo name=emcpower15a
3076 pci@2,600000/SUNW,emlxs@0/fp@0,0 c1t57d165s0 FA 13cA active alive 0 0
3075 pci@12,600000/SUNW,emlxs@0/fp@0,0 c3t52d165s0 FA 4cA active alive 0 0
I fired below awk command and got some error
awk '/^emc/{p=$0}!/^emc/&&NF{A[p]++}END{for(c in A) print c,A[c]}' OFS=" - " /tmp/dev1
awk: syntax error near line 1
awk: bailing out near line 1
So I used nawk which ran successfully however didn't produce expected output.
nawk '/^emc/{p=$0}!/^emc/&&NF{A[p]++}END{for(c in A) print c,A[c]}' OFS=" - " /tmp/dev1
- 696
---------- Post updated at 08:43 AM ---------- Previous update was at 08:40 AM ----------
Do you expect this code to work when you change the file format?
Read it carefully and you will understand why it didn't work.
Here is something that will work for your current input:
nawk -F'=' '
/emcpower/ {
d = $2
}
!/emcpower/ && NF {
A[d]++
}
END {
for ( c in A )
print c, A[c]
}
' OFS=' - ' file
Please make sure that you post representative samples that are similar to your original input file data in future, otherwise it is a waste of time for you and people who are trying to help...
awk -F'=' ' # Set = as field separator
/emcpower/ { # Search for pattern: emcpower
d = $2 # If found, assign d to 2nd field (disk name)
}
!/emcpower/ && NF { # Search for not pattern: emcpower and NF>=1
A[d]++ # Create and increment array indexed by disk name
}
END { # END block
for ( c in A ) # For each element in array
print c, A[c] # Print disk name and count
}
' OFS=' - ' file # Set ' - ' as output field separator
Read the nawk manual for further reference: man nawk