+2 votes
in Programming Languages by (71.8k points)
In my file, one of the columns has some special string and I want to know its count. The columns are tab separated. How can I find its total count using awk/gawk command?

1 Answer

+1 vote
by (348k points)
selected by
 
Best answer

If your file is not zipped, you can try the following awk command:

awk 'BEGIN{FS="\t";}{if ($column_number=="your_string") i++}END{print i}' filename

If your file is zipped, you can try the following awk command:

zcat zipped_file | awk 'BEGIN{FS="\t";}{if ($column_number=="your_string") i++}END{print i}'

Replace column_number with the column number in your file and your_string with your special string.


...