0

I am trying to find out how to stream a file so that if gives me back how many times a certain field label occurred.

File example:
Cat black 100 home lost
Dog brown 632 street lost
Dog black 839 home owned
Pig pink 123 mud farm
Dog white 345 street lost

I would like to find out how many times does "Dog" appear in the file using the AWK command if possible or maybe even another command that is capable.

2
Contributors
1
Reply
2
Views
12 Years
Discussion Span
Last Post by perniciosus
0

I am trying to find out how to stream a file so that if gives me back how many times a certain field label occurred.

File example:
Cat black 100 home lost
Dog brown 632 street lost
Dog black 839 home owned
Pig pink 123 mud farm
Dog white 345 street lost

I would like to find out how many times does "Dog" appear in the file using the AWK command if possible or maybe even another command that is capable.

awk 'BEGIN { num = 0 } ; END { print num } ; /dog/ { num = num + 1 }' < input.file

Change regex to fit your need...
Or put in .awk file and run as program, im not to much into how those files takes arguments but it should be doable...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.