-2

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
  • 2
    Please edit the question and add some sample input and expected output. Commented Jun 25, 2020 at 7:43

1 Answer 1

1
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.