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   -   Original Discussion by nikhil jain
nikhil jain nikhil jain is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 16 October 2017, 6:26 AM EDT
Location: Bangalore
Posts: 174
Thanks: 40
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 05:03 AM.. Reason: Get rid of nested CODE tags.
Sponsored Links
    #2  
Old Unix and Linux 06-12-2017   -   Original Discussion by nikhil jain
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is online now Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 23 November 2017, 1:28 PM EST
Location: San Jose, CA, USA
Posts: 10,677
Thanks: 573
Thanked 3,738 Times in 3,190 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 08-02-2017   -   Original Discussion by nikhil jain
nikhil jain nikhil jain is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 16 October 2017, 6:26 AM EDT
Location: Bangalore
Posts: 174
Thanks: 40
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; 08-02-2017 at 08:31 AM..
    #4  
Old Unix and Linux 08-02-2017   -   Original Discussion by nikhil jain
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 23 November 2017, 1:17 PM EST
Location: Aachen, Germany
Posts: 11,652
Thanks: 323
Thanked 3,620 Times in 3,325 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 (08-03-2017)
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 07:22 AM
Read first column and count lines in second column using awk Padavan Shell Programming and Scripting 5 10-25-2015 06:57 AM
Count column lawsongeek UNIX for Dummies Questions & Answers 6 06-18-2014 04: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 02: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 08:56 PM



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