Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print file to stdout -- character by character 2

Status
Not open for further replies.

aehem

Technical User
Oct 29, 2007
3
Here is my question (if you want to know why all this, please see the p.s.):

Is it possible to print a text file's contents to stdout on a character-by-character basis? I figure, the script would have to be able to enumerate/index all or a section of characters in the text file and then move through them consecutively, printing them faithfully to stdout...

Let me know what you think and thank you in advance!

p.s. In the end I would like to use a screencasting device to record the output of the trick -- make it seem like I'm typing the text :)
 
Hi

You forgot to mention what shell you use. With [tt]bash[/tt] is one line :
Bash:
while IFS='' read -r -n 1 -d '' c; do echo -n "$c"; usleep 100000; done < /input/file

Feherke.
 
Thank you -- that seems to do what I asked for, although usleep is not recognized in my bash shell and without this of course the text is simply output too fast...

While I was waiting for a reply last night, however, I found that an Emacs macro does pretty much what I want by jumping between split screens, yanking and pasting characters one by one from one to the other. I'll be able to direct my screencasting app to the respective output buffer and, voila, I should be ready to move on.

Thanks again, though, as simply the possibility to ask experts in a forum like this clearly contributed to me finding a solution.

 
Hi

The [tt]usleep[/tt] should be a standalone executable. Mine comes from one of the SuSE's administration packages, but I saw it in other distributions too. And BusyBox has one too.

Anyway, it is simple to make one for yourself. You just have to call the [tt]usleep()[/tt] C function ( man 3 usleep ) and pass it the command line argument :
Code:
#include <stdlib.h> 
#include <unistd.h> 

[b]int[/b] main([b]int[/b] argc,[b]char[/b] *argv[])
{
  [b]if[/b] (argc<=1) {
    printf([i]"wrong usage. try : usleep microseconds\n"[/i]);
    [b]return[/b] 1;
  }
  [b]long[/b] micro=atoi(argv[1]);
  usleep(micro);
  [b]return[/b] 0;
}
Code:
cc -o usleep usleep.c

Feherke.
 
Feherke, I'd change this:
long micro=atoi(argv[1]);
with this:
long micro=atol(argv[1]);
 
There's also Randtype, a command line utility that does what you described and has various tunable parameters such as typo frequency.
 
Thank you guys -- I got the one-liner working and the randtype utility is right on, too. Amazing!

If this post is still up by the time I've completed my animation project I will go ahead and post the link...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top