Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Trying to find the Count of Other Column

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 06-12-2017
nikhil jain nikhil jain is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 10 August 2017, 6:10 AM EDT
Location: Bangalore
Posts: 171
Thanks: 39
Thanked 2 Times in 2 Posts
Trying to find the Count of Other Column

Content of My File below :-


Code:
Name,Direport,Management chain,Owner,Entity,Oilv name,Oilv policy class,Oilv policy type,Oilv type severity,Entity status,Acked,Resolution,Plan to fix by,Id entity,Entity link,Ticket link,Comment
AnksX,AnksX,AnksX,anksd (AnksX),SpectreX,EnvironmentsX,availability,risk,High,ACTIVE,YES,BY_DESIGN,UNKNOWN,3142959,https://pe.x.com/entity/3142959#gol4Js,-
AnksX,AnksX,AnksX,anksd (AnksX),SpectreX,EnvironmentsX,availability,risk,High,ACTIVE,NO,NO PLAN,UNKNOWN,2458850,https://pe.x.com/entity/2458850#gol4Js,-
AnksX,AnksX,AnksX,anksd (AnksX),SpectreX,EnvironmentsX,availability,risk,High,ACTIVE,YES,BY_DESIGN,UNKNOWN,3349649,https://pe.x.com/entity/3349649#gol4Js,-
AnksX,AnksX,AnksX,anksd (AnksX),SpectreX,Bad ASG distribution in Prod,availability,risk,Critical,ACTIVE,NO,NO PLAN,UNKNOWN,26912320,https://pe.x.com/entity/26912320#sdabX,NA,-
AnksX,AnksX,AnksX,anksd (AnksX),SpectreX,AWX3,availability,risk,High,ACTIVE,NO,NO PLAN,UNKNOWN,2459346,https://pe.x.com/entity/2459346#s3JavaClientCrossRegionCalls,NA,-
AnksX,AnksX,AnksX,anksd (AnksX),SpectreX,Bad ASG distribution in Prod,availability,risk,Critical,ACTIVE,NO,NO PLAN,UNKNOWN,3984911,https://pe.x.com/entity/3984911#sdabX,NA,-
AnksX,AnksX,AnksX,anksd (AnksX),SpectreX,AWX3,availability,risk,High,ACTIVE,NO,NO PLAN,UNKNOWN,4082037,https://pe.x.com/entity/4082037#s3JavaClientCrossRegionCalls,NA,-
AnksX,AnksX,AnksX,anksd (AnksX),SpectreX,AWX3,availability,risk,High,ACTIVE,NO,NO PLAN,UNKNOWN,24691230,https://pe.x.com/entity/24691230#s3JavaClientCrossRegionCalls,NA,-
AnksX,AnksX,AnksX,anksd (AnksX),SpectreX,EnvironmentsX,availability,risk,Critical,ACTIVE,NO,NO PLAN,UNKNOWN,24691230,https://pe.x.com/entity/24691230#Stejx,NA,-
AnksX,AnksX,AnksX,anksd (AnksX),SpectreX,EnvironmentsX,availability,risk,High,ACTIVE,NO,NO PLAN,UNKNOWN,24691230,https://pe.x.com/entity/24691230#gol4Js,-


awk i wrote


Code:
awk -F "," '/High|Critical/' temp10.csv | grep -w "availability"  | awk -F "," '{print $6}' | sort | uniq -c

O/p I'm getting


Code:
   3 AWX3
   2 Bad ASG distribution in Prod
   5 EnvironmentsX

O/p I want is


Code:
Oilv name                               Total Count   ACKED    NOT_ACKED
 AWX3                                      3                     0                   3
 Bad ASG distribution in Prod 2                     0                 2
 EnvironmentsX                        5                     2                3

ACKED is the 11th column, i tried below solution but to no avail


Code:
awk -F "," '/High|Critical/' temp10.csv | grep -w "availability"  | grep -w "YES" | awk -F "," '{print $6}' | sort | uniq -c

awk -F "," '/High|Critical/' temp10.csv | grep -w "availability"  | grep -w "NO" | awk -F "," '{print $6}' | sort | uniq -c


Last edited by Don Cragun; 06-12-2017 at 04:03 AM.. Reason: Get rid of nested CODE tags.
Sponsored Links
    #2  
Old Unix and Linux 06-12-2017
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 18 August 2017, 4:54 AM EDT
Location: San Jose, CA, USA
Posts: 10,462
Thanks: 533
Thanked 3,660 Times in 3,123 Posts
Maybe you want something more like:

Code:
awk -F, '
BEGIN {	m = 9
}
$9 ~ /^(High|Critical)$/ && $7 == "availability" {
	c[$6]++
	n[$6] += $11 == "NO"
	y[$6] += $11 == "YES"
	if(length($6) > m) m = length($6)
}
END {	printf("%*s  Total Count  ACKED  NOT_ACKED\n", m, "Oilv name")
	for(i in c)
		printf("%*s  %11d  %5d  %9d\n", m, i, c[i], y[i], n[i])
}' temp10.csv

which with your sample input produces the output:

Code:
                   Oilv name  Total Count  ACKED  NOT_ACKED
                        AWX3            3      0          3
               EnvironmentsX            5      2          3
Bad ASG distribution in Prod            2      0          2

The Following User Says Thank You to Don Cragun For This Useful Post:
nikhil jain (06-12-2017)
Sponsored Links
    #3  
Old Unix and Linux 2 Weeks Ago
nikhil jain nikhil jain is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 10 August 2017, 6:10 AM EDT
Location: Bangalore
Posts: 171
Thanks: 39
Thanked 2 Times in 2 Posts
Hi ALL,


How do i get that with the extra row? Sum of all the numeral columns.


Code:
Code:
Oilv name  Total Count  ACKED  NOT_ACKED
                        AWX3            3      0          3
               EnvironmentsX            5      2          3
Bad ASG distribution in Prod            2      0          2
TOTAL                                      10        2        8


Last edited by nikhil jain; 2 Weeks Ago at 07:31 AM..
    #4  
Old Unix and Linux 2 Weeks Ago
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 18 August 2017, 2:12 PM EDT
Location: Aachen, Germany
Posts: 11,173
Thanks: 287
Thanked 3,443 Times in 3,172 Posts
No idea by yourself on how to go about it?

Building on what Don Cragun posted, try

Code:
awk -F, '
BEGIN   {m = 9
        }
$9 ~ /^(High|Critical)$/ &&
$7 == "availability"            {c[$6]++
                                 n[$6] += $11 == "NO"
                                 y[$6] += $11 == "YES"
                                 if(length($6) > m) m = length($6)
                                }
END                             {printf("%*s  Total Count  ACKED  NOT_ACKED\n", m, "Oilv name")
                                 for(i in c)    {printf("%*s  %11d  %5d  %9d\n", m, i, c[i], y[i], n[i])
                                                 CT += c[i]
                                                 NT += n[i]
                                                 YT += y[i]
                                                }
                                 printf ("%*s  %11d  %5d  %9d\n", m, "Total", CT, YT, NT)

                                }
'  temp10.csv
                   Oilv name  Total Count  ACKED  NOT_ACKED
Bad ASG distribution in Prod            2      0          2
                        AWX3            3      0          3
               EnvironmentsX            5      2          3
                       Total           10      2          8

The Following User Says Thank You to RudiC For This Useful Post:
nikhil jain (2 Weeks Ago)
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Column 2 string count in Column 3 nikhil jain Shell Programming and Scripting 6 06-15-2016 06:22 AM
Read first column and count lines in second column using awk Padavan Shell Programming and Scripting 5 10-25-2015 05:57 AM
Count column lawsongeek UNIX for Dummies Questions & Answers 6 06-18-2014 03:12 PM
Find lines with matching column 1 value, retain only the one with highest value in column 2 pathunkathunk Shell Programming and Scripting 3 03-06-2013 01:09 AM
find expression with awk in only one column, and if it fits, print whole column glev2005 Shell Programming and Scripting 2 01-26-2010 07:56 PM



All times are GMT -4. The time now is 02:16 PM.