Using awk to count the number of occurrences of a word in a column

后端 未结 6 1796
难免孤独
难免孤独 2020-12-03 10:28
03/03/2014 12:31:21 BLOCK 10.1.34.1 11:22:33:44:55:66

03/03/2014 12:31:22 ALLOW 10.1.34.2 AA:BB:CC:DD:EE:FF

03/03/2014 12:31:25 BLOCK 10.1.34.1 55:66:77:88:99:AA
<         


        
6条回答
  •  甜味超标
    2020-12-03 11:16

    The error in your awk invocation is that, in your "END" block, you have print $count. That takes the content of the count variable, assumes it is an integer, and attempts to find the corresponding field in the last line of input. What you really want is just print count, as that just prints the value in the count variable. It's sometimes easy to mix up different variable referencing schemes between bash, awk, python, etc., so it's an easy mistake to make.

提交回复
热议问题