I'm trying to match the word United States
from a folder containing 5 csv files, However, the command I'm using checks for single occurrence in the line. I also want to sum other two columns based on the matched string.
awk -F "," '{if (/United States/) sum_1 += $2;sum_2 += $3} END {print sum_1, sum_2}' Files/*.csv
Yes I'm trying to check more than one occurrences in the line with awk
.
So if the line has two occurrences of United States it should give :
2
awk '/United States/{x++;}END{print x}' Files/*csv
Example file
United States,1,2,3
Donald TRump,1,2,3
United States,1,2,3,United States