Skip to main content
Add formatting to make sample input and output easier to distinguish
Source Link
AdminBee
  • 23.6k
  • 25
  • 56
  • 77

I'm trying to match the word United StatesUnited 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 awkawk.

So if the line has two occurrences of United States it should give : 2

2
awk '/United States/{x++;}END{print x}' Files/*csv

awk '/United States/{x++;}END{print x}' Files/*csvExample file

United States,1,2,3
Donald TRump,1,2,3
United States,1,2,3,United States

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

United States,1,2,3
Donald TRump,1,2,3
United States,1,2,3,United States

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
deleted 2 characters in body
Source Link

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 += $12;sum_2$2;sum_2 += $17$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

United States,1,2,3
Donald TRump,1,2,3
United States,1,2,3,United States

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 += $12;sum_2 += $17} 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

United States,1,2,3
Donald TRump,1,2,3
United States,1,2,3,United States

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

United States,1,2,3
Donald TRump,1,2,3
United States,1,2,3,United States
added 301 characters in body
Source Link

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 += $12;sum_2 += $17} 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

United States,1,2,3
Donald TRump,1,2,3
United States,1,2,3,United States

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 += $12;sum_2 += $17} END {print sum_1, sum_2}' Files/*.csv

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 += $12;sum_2 += $17} 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

United States,1,2,3
Donald TRump,1,2,3
United States,1,2,3,United States
Source Link
Loading