0

I want to create a little animation in the stdout of the terminal using printf. So far I figured out how to replace the last line with

#!/bin/csh -f        
printf "text1"
printf "text2"
sleep 1
printf "\r replaced text2"

How do I replace both lines?

printf "\r\r replace text1"

does not work....

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
MichaelScott
  • 387
  • 1
  • 3
  • 21

2 Answers2

2

You need to use the cuu1 terminfo capability to move the cursor up.

printf "foobar"
tput cuu1
printf "baz"
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • Note that `tput cuu1` will move the cursor up one row, but it will stay on the same column. Depending on what you're doing, you might want to print another `"\r"`, or perhaps use whatever `tput` code moves the cursor to the beginning of the line. Note also that if the new text is shorter than the old text, it won't replace all of it: `printf "original\rNEW\n"` prints `NEWginal`. – Keith Thompson Nov 06 '13 at 20:16
0

Ignacios answer brought me on the right track! Thanks!! Nevertheless:

    tput cuu N

sets your cursor N lines back.

MichaelScott
  • 387
  • 1
  • 3
  • 21