The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
grep unix.com with google



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-26-2009
Registered User
 

Join Date: Sep 2009
Location: Kolkata,India
Posts: 188
Printing output with interval between letters

I want to print/echo an output "This is the name of the game" where each letter will be printed/echoed after an interval of 1 sec
  #2 (permalink)  
Old 11-26-2009
vidyadhar85's Avatar
Moderator(The Tutor)
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,453
this will do..

Code:
echo "This is the name of the game"|awk '{for(i=1;i<=NF;i++){printf $i" ";system("sleep 1")}}END{print}'

  #3 (permalink)  
Old 11-26-2009
Registered User
 

Join Date: Sep 2009
Location: Kolkata,India
Posts: 188
I got the following output:

Code:
This is the name of the game This is the name of the game

that is the output printed twice instead of once.

Also, the output was printed with an interval of 1 sec between words and not each character/letter.
  #4 (permalink)  
Old 11-26-2009
dj - the student
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 667
Quote:
Originally Posted by vidyadhar85 View Post
this will do..

Code:
echo "This is the name of the game"|awk '{for(i=1;i<=NF;i++){printf $i" ";system("sleep 1")}}END{print}'
This will echo words by word..
For character by character, try:


Code:
echo "This is the name of the game"|awk '{ ORS="";while(i++<length($0)) { print substr($0,i,1); system("sleep 1"); } }'

  #5 (permalink)  
Old 11-26-2009
Registered User
 

Join Date: Sep 2009
Location: Kolkata,India
Posts: 188
Works fine except that the prompt comes immediately after the output:


Code:
This is the name of the game[root@wiki ~]#

  #6 (permalink)  
Old 11-26-2009
dj - the student
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 667
Quote:
Originally Posted by proactiveaditya View Post
Works fine except that the prompt comes immediately after the output:


Code:
This is the name of the game[root@wiki ~]#
ok.Try:


Code:
echo "This is the name of the game"|awk '{ ORS="";while(i++<length($0)) { print substr($0,i,1); system("sleep 1"); }printf "\n"; }'

Bits Awarded / Charged to dennis.jacob for this Post
Date User Comment Amount
11-26-2009 Anonymous good 100
  #7 (permalink)  
Old 11-26-2009
Registered User
 

Join Date: Sep 2009
Location: Kolkata,India
Posts: 188
While i run the above code snippet ctrl+c doesn't have any effect. Why is it so?
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
printing portion of the output usind sed/awk unahb1 Shell Programming and Scripting 4 10-01-2009 12:45 PM
compare the interval of 2 numbers of input2with interval of several numbers of input1 repinementer Shell Programming and Scripting 1 07-21-2009 10:52 PM
output the letters of the alphabet with the number of occurrences svd High Level Programming 10 12-03-2007 10:19 AM
printing output more than 13 Krrishv Shell Programming and Scripting 2 01-22-2007 05:35 AM
Printing output to the monitor jyotipg Shell Programming and Scripting 2 06-22-2004 06:41 AM



All times are GMT -4. The time now is 02:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0