How to watch for count of new lines in tail

command-line-interfacetailwatch

I want to do something like this:

watch tail -f | wc -l
#=> 43
#=> 56
#=> 61
#=> 44
#=> ...

It counts new lines of tail each second

/ Linux, CentOs

To be more clear. I have got something like this:

tail -f /var/log/my_process/*.log | grep error

I am reading some error messages. And now I want to count them. How many ~ errors I have got in a second. So one line in a log is one error in a proccess.

Best Answer

I've recently discovered pv, and it's really cool, you could do something like

tail -f logfile | pv -i2 -ltr > /dev/null

  • -i2 = count every 2 seconds
  • -l = count lines
  • -t = print time
  • -r = show rate