i require to count the number of occurrences of first field in txt file and to print output file as two column file having first field of input file & no. of occurrences of fist field in input file
1 Answer
awk '{ count[$1]++ } END { for (field in count) print field, count[field] }' file.txt That is, use the first field as the key in the associative array count. For each record, increment the value corresponding to the field. At the end, loop through the keys of count and print them and the associated values.