Skip to main content
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264
added 223 characters in body
Source Link

I want to counts number of rows with certain columns equal to specific value. Below is a section of the input file:

enter image description here

The first row is the header. I want to count the number of rows that column 1 equal to 2002, column 3 equal to Female, column 4 equal to 18--20, column 8 equal to CO.

I tried the below command:

awk  -F "," '$0==2002'$1=="2002" && $2="Female"&&$3="Female"&& $3="18$4="18--20" && $7$8 ="CO"{count++};END{print count;}' newData.csv 

But it didn't work.

I updated the command to above but it still not working. The number it print out is 1116 which is incorrect. This is just the number that column 1 equal to 2002. I need to count the rows that satisfy all the conditions.

I want to counts number of rows with certain columns equal to specific value. Below is a section of the input file:

enter image description here

The first row is the header. I want to count the number of rows that column 1 equal to 2002, column 3 equal to Female, column 4 equal to 18--20, column 8 equal to CO.

I tried the below command:

awk  -F "," '$0==2002 && $2="Female"&& $3="18--20" && $7 ="CO"{count++};END{print count;}' newData.csv 

But it didn't work.

I want to counts number of rows with certain columns equal to specific value. Below is a section of the input file:

enter image description here

The first row is the header. I want to count the number of rows that column 1 equal to 2002, column 3 equal to Female, column 4 equal to 18--20, column 8 equal to CO.

I tried the below command:

awk  -F "," '$1=="2002" && $3="Female"&& $4="18--20" && $8 ="CO"{count++};END{print count;}' newData.csv

But it didn't work.

I updated the command to above but it still not working. The number it print out is 1116 which is incorrect. This is just the number that column 1 equal to 2002. I need to count the rows that satisfy all the conditions.

Source Link

Count number of rows with certain columns equal to specific value

I want to counts number of rows with certain columns equal to specific value. Below is a section of the input file:

enter image description here

The first row is the header. I want to count the number of rows that column 1 equal to 2002, column 3 equal to Female, column 4 equal to 18--20, column 8 equal to CO.

I tried the below command:

awk  -F "," '$0==2002 && $2="Female"&& $3="18--20" && $7 ="CO"{count++};END{print count;}' newData.csv 

But it didn't work.