How to watch for count of new lines in tail

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

Here's a quick and dirty method. You basically want to break the tail and the watch wc into separate parts, and do something like:

tail -f /var/log/my_process/*.log |grep error > /tmp/error.lines &
watch wc /tmp/error.lines

at which point, you can do math to get an errors/sec number. But, if you're just doing this for an one-off examination of your error rate, quick-and-dirty might be good enough.


In case pv is not available it can be done with perl:

Every one second:

tail -f  recycleBack*out  | perl -e 'while (<>) {$l++;if (time > $e) {$e=time;$i++;print "$i=> $l\n";$l=0}}'

Every 10 seconds

tail -f  recycleBack*out  | perl -e 'while (<>) {$l++;if (time > $e+10) {$e=time;$i++;print "$i=> $l\n";$l=0}}'

Sample output:

1=> 1
2=> 1523
3=> 1339
4=> 1508
5=> 1785
6=> 1587
7=> 1770
8=> 1432
9=> 1339
10=> 1555
11=> 1663
12=> 1693
13=> 1647