开发者

awk can't get my for i loop to work

I'm trying to loop in a log file and add occurrences of one of the field.

I know that the field #8 will have the occurrences I want to add, and that the field will contain a number between 1 and 924.

So far I had this awk one-liner:

awk '{count[$8]++}END{for(j in count) print j, count[j]" HIT"}' myfile.txt

But, I would like awk to output the numbers for witch it didn't find occurrences and print 0 next to it.

For example:

1 5 HIT
2 0 HIT
3 55 HIT

I tried this:

awk '{for(i开发者_运维百科=1;i<=924;i++) print i, count[$8]++}' myfile.txt

EDIT: I also tried this

awk '{count[$8]++}END{for(i=1;i<925;i++) print i, count[i]" HIT"}' myfile.txt

It gave me this:

919  HIT
920  HIT
921  HIT
922  HIT
923  HIT
924  HIT

And I'm sure there are counts for all of those.

Any help would be appreciated!


try this

awk '{count[$8]++}END{for(i=1;i<925;i++) print i, count[i]" HIT"}' myfile.txt

I hope this helps.

P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜