Trying to find the Count of Other Column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trying to find the Count of Other Column
# 1  
Old 06-12-2017
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.
# 2  
Old 06-12-2017
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

This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 08-02-2017
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 08-02-2017
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

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find the count of IP addresses that belong to different subnets and display the count?

Hi, I have a file with a list of bunch of IP addresses from different VLAN's . I am trying to find the list the number of each vlan occurence in the output Here is how my file looks like 1.1.1.1 1.1.1.2 1.1.1.3 1.1.2.1 1.1.2.2 1.1.3.1 1.1.3.2 1.1.3.3 1.1.3.4 So what I am trying... (2 Replies)
Discussion started by: new2prog
2 Replies

2. Shell Programming and Scripting

awk to find maximum and minimum from column and store in other column

Need your support for below. Please help to get required output If column 5 is INV then only consider column1 and take out duplicates/identical rows/values from column1 and then put minimum value of column6 in column7 and put maximum value in column 8 and then need to do subtract values of... (7 Replies)
Discussion started by: as7951
7 Replies

3. Shell Programming and Scripting

Column 2 string count in Column 3

My I/p is Col1|Col2|Col3 2116209997932|POSIX INC|POSIX 2116209997933|POSIX INC|POSIX 2116210089479|POSIX INC|POSIX 2116210180502|POSIX INC|POSIX 2116210512279|POSIX INC|Aero 2116210516838|POSIX INC|POSIX 2116210534342|POSIX INC|postal 2116210534345|POSIX INC|postal ... (6 Replies)
Discussion started by: nikhil jain
6 Replies

4. Shell Programming and Scripting

Read first column and count lines in second column using awk

Hello all, I would like to ask your help here: I've a huge file that has 2 columns. A part of it is: sorted.txt: kss23 rml.67lkj kss23 zhh.6gf kss23 nhd.09.fdd kss23 hp.767.88.89 fl67 nmdsfs.56.df.67 fl67 kk.fgf.98.56.n fl67 bgdgdfg.hjj.879.d fl66 kl..hfh.76.ghg fl66... (5 Replies)
Discussion started by: Padavan
5 Replies

5. UNIX for Dummies Questions & Answers

Count column

how do i count column in a file. test1,test2,test3,,, = 5 columns (6 Replies)
Discussion started by: lawsongeek
6 Replies

6. Shell Programming and Scripting

Find lines with matching column 1 value, retain only the one with highest value in column 2

I have a file like: I would like to find lines lines with duplicate values in column 1, and retain only one based on two conditions: 1) keep line with highest value in column 3, 2) if column 3 values are equal, retain the line with the highest value in column 4. Desired output: I was able to... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

7. Shell Programming and Scripting

Need Count of Column

Need help on count AL06 AL06_71 A=1 it=1 90 AL06 AL06_72 A=1 it=1 60 AL06 AL06_73 A=1 it=1 80 AL06 AL06_7 A=2 it=1 0 AL06 AL06_7 A=2 it=1 0 AL06 AL06_7 A=2 it=1 0 AL07 AL07_71 A=1 it=1 40 AL07 AL07_72 A=1 it=1 40 AL07 AL07_73 A=1 it=1 70 AL08 AL08_7 A=2 it=1 0 1 AL08 AL08_7 A=2 it=1... (2 Replies)
Discussion started by: asavaliya
2 Replies

8. Shell Programming and Scripting

Column value and it's count

Hi, i have data like a b a a b c d ... I have to output info of each distinct value that appears in the column and the count of it a-3,b-2,c-1,d-1 Is there a single line command using awk or sed to accomplish this? Thanks, -srinivas yelamanchili (7 Replies)
Discussion started by: ysrini
7 Replies

9. UNIX for Advanced & Expert Users

column count

I am making a script in bash shell and need to find out how many columns are in each row. I tried using awk '{print NF}' which will give me the number of columns for each row of the file all at once which is not what i want. I am trying to read each line individual from a file and want to know... (6 Replies)
Discussion started by: HackerSeabass
6 Replies

10. Shell Programming and Scripting

find expression with awk in only one column, and if it fits, print whole column

Hi. How do I find an expression with awk in only one column, and if it fits, then print that whole column. 1 apple oranges 2 bannanas pears 3 cats dogs 4 hesaid shesaid echo "which number:" read NUMBER (user inputs number 2 for this example) awk " /$NUMBER/ {field to search is field... (2 Replies)
Discussion started by: glev2005
2 Replies
Login or Register to Ask a Question