How to make a cat / tac stream at a given line / second speed?

Imagine you have a large log file named "filename"

if you tail -f filename then you have a stream only if the filename is updated

if you are filename cat then you have a stream but cannot read it if you have a processor newer than intel 8088

if you cat filename | more then you have a stream, page by page and will probably break your whitespace key

How can I list the file at a given speed (ex: 1 line every 0.05 seconds) so I have time to read, but I don't have to press the spacebar hundreds of times?

(I don't use | grep because in my special case I don't know exactly what to look for)

+3


source to share


4 answers


yes | pv --quiet --rate-limit 10

      

I used yes

here to get a quick source of text; pv

is an extremely useful tool for many reasons, but one of its features is the speed limiter. You have to say that it is quiet, so it does not output a progress bar. Limit in bytes per second.



See also: https://superuser.com/questions/526242/cat-file-to-terminal-at-particular-speed-of-lines-per-second

+7


source


Using

perl -MTime::HiRes=usleep -pe '$|=1;usleep(300000)'
#or
perl -pe 'select(undef,undef,undef,0.3)'

      

you can add the above as a shell function in your ~/.profile

eg.

slowcat

slowcat() {
    perl -MTime::HiRes=usleep -pe '$|=1;usleep(300000)' "$@"
}

      



will accept filenames as well as input from pipes,

slowcat filenames....
command | slowcat

      

The following will give the output as a typical movie computer screen or connection, for example via a 300Baud modem ...

perl -MTime::HiRes=usleep -ne '$|=1;while($c=getc(*stdin)){usleep(33000);print $c}'

      

+4


source


Perhaps something like this:

#!/bin/bash


while read -r line; do 
   echo "$line"; # do whatever you want with line
   sleep 0.05

done < file

      

+2


source


Hope this helps:

 cat filename|awk  '{print $0 ; system("sleep 0.05")}'

      

Since the above solution is messy according to most people, I suggest the following one liner:

while read line; do echo $line; sleep 0.05 ; done < filename

      

+1


source







All Articles