Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove two lines from terminal output

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.

like image 994
P O'Conbhui Avatar asked Dec 22 '22 22:12

P O'Conbhui


1 Answers

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*'
like image 92
Ignacio Vazquez-Abrams Avatar answered Jan 03 '23 15:01

Ignacio Vazquez-Abrams