#!/bin/bash cmd=$(echo ${@}) time_buffer=3 rm -f buf now=$(date +%s) ts=$d while read contents do echo $contents >> buf # echo now=$now, ts=$ts if (($ts + $time_buffer < $now)) then ts=$now echo "$d Buf size: " $(wc -l buf) >/dev/stderr $cmd < buf rm buf fi now=$(date +%s) done echo "$d Buf size: " $(wc -l buf) >/dev/stderr $cmd < buf rm buf