I want to do some simple computation of the number of lines per minute added to a log file. I also want to store the count for each second.
What I need is the output of the following command as a list which will be updated every second:
watch -n1 'wc -l my.log'
How can I output the 'update' of the 'watch' command as a list?
Best Answer
You can use the
-t
switch towatch
which causes it not to print header. However, that will still clear the screen so you might be better off with a simple shell loop:One of the advantages is, that you can easily add other commands (e.g.
date
) and/or pipe the output throughsed
to reformat it. By the way, if you swapsleep 1
withwc
in the loop, it will automatically terminate on errors.