2

I'd like to know how many average lines are written to a file per minute.

  • 1
    Could you be more explicit? E.g., does there need to be a running LPM status, or is just a calculation at the end sufficient? Is this wall-clock time, CPU time, etc.? Do you have a specific definition of "line" – rickhg12hs Oct 23 '13 at 9:18
5

You could do:

tail -fn0 the-file | pv -lri60 > /dev/null

That will give you a number of lines per second though.

Otherwise:

{
  cat > /dev/null
  while sleep 60; do
    wc -l
  done 
} < the-file

(beware that won't be exactly accurate as the sleep 60 won't guarantee that is done exactly every 60 seconds).

  • So where is the averaging done? – rickhg12hs Oct 23 '13 at 10:08
  • @rickhg12hs, in the wc -l done on the last lines added within the last 60 seconds. – Stéphane Chazelas Oct 23 '13 at 10:21
  • @Stephane, so it's a count, not an average. But perhaps that's what the OP really wanted. – rickhg12hs Oct 23 '13 at 13:48
  • First works for me; just changing lri60 to lri1 gives immediate feedback :-) – kouton May 21 '15 at 16:58
  • @StéphaneChazelas How do you use grep in between tail and pv to filter output? It's not working for me.. – kouton May 21 '15 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy