Reputation: 1223
Given that two lines have been printed out in the terminal, is it possible to delete both of them so they may be replaced with two new lines?
I know you can use \r to replace 1 line (well, to move the cursor to the start of the line), but is there any way of doing this for the line above?
As an example, I'm running a program for computing the eigenfunctions of the Schrodinger equation and I want to keep an eye on how my variables are changing as it's being run, so I'd like an output like:
Param 1: xxxxxxx
Param 2: xxxxxxx
So I'd have the two parameters on two lines so they can be easily read and they'd be updated on each iteration of the program's matching function.
Upvotes: 4
Views: 2332
Reputation: 365
You could also use $(tput cuu 2)
instead of $(tput cuu1)$(tput cuu1)
-- Aesthir
Upvotes: 7
Reputation: 798486
The cuu1
terminal capability allows you to go up a line. Pass it to tput
in order to read the character sequence from the terminfo/termcap database, and then echo
it twice.
echo -e '123\nabc\n'"$(tput cuu1)$(tput cuu1)"'*\n*'
Upvotes: 7