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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refresh stdoutput

Status
Not open for further replies.

domenicodl

Programmer
Jul 2, 2011
15
IT
Hello,
I'd like to refresh the stdoutput. Suppose that I have the following program

BEGIN{
print "execution";
for(i = 0; i<4; i++)
print i;
}

the output is
execution
0
1
2
3

rather I would like to refresh the stdouput as the for loop runs, thus just one line of the stdoutput updates its value without having a long sequence of print.
It is like:

execution
0 then this becomes 1, 2....

Thank you in advance.

I checked "fflush" and system("") but none of them helped me, maybe I used them mistakenly.
 
Hi

That is usually solved using your old friend, the carriage return ( [tt]\r[/tt] ) character :
Code:
BEGIN {
  print "execution"
  for (i=0; i<4; i++)
    printf "\r%d", i
}
[ul]
[li]Used the [tt]printf[/tt] statement because it not outputs the [tt]ORS[/tt]. ( The alternative is to use [tt]print[/tt] but set [tt]ORS[/tt] to empty string. )[/li]
[li]Output the carriage return character which has the effect of moving the cursor to the beginning of current line.[/li]
[/ul]


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top