views:

33

answers:

1

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.

+2  A: 

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*'
Ignacio Vazquez-Abrams
Absolutely perfect! Can't believe I've never heard of tput before. This'll help a whole lot more than with just this project.