From a given file I have to find out what are all values for "Application States :" and how many of them have same state.
eg :
If there are possible states in file :
Application States : Normal
Application States : Terminated
Application States : Pending
and if there are 10 Normal, 2 Terminated and 15 Pending applications then I want to have some script or unix grep command to show something like this :
Application States : Normal : total = 10
Application States : Terminated : total = 02
Application States : Pending : total = 15
What would be the exact unix command or script to achieve above?
You didn't provide any actual sample input, you didn't answer my question about what operating system you're using, and the application "states" you've shown us look more like possible values for "application status" than "application state". So, if Aia's suggestion doesn't work, you might also try:
awk '
/^Application Sta/ {
c[$0]++
if(length($0) > m)
m = length($0)
}
END { for(i in c)
printf("%-*s : total = %02d\n", m, i, c)
}' file
If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk .
Is it possible to post a few copy and paste lines from the original file?
Either the white spacing or the "Application States" string is not accurate in your example.
I'm very glad that we finally got something to work for you...
Note that the data you posted in message #8 (and deleted 37 minutes later) did not look anything like the data you included in posts #1 and #3. Leading spaces make a difference. Having Application State : instead of Application States : makes a difference. Having six spaces between the colon and the state instead of one space makes a difference.
You don't have to show us confidential data to get our help, but you do need to show us representative data. The commands you said you used in post #3 would have produced absolutely no output (just like Aia's awk script and my awk script) when given your real data instead of the data you showed us in post #1.