How to use clear screen CLS command line to clear only two above lines?

2.9k views Asked by At

I am running the following lines,

@echo off
echo hi
echo hello
echo bye
pause
cls
echo welcome
echo once again
pause

output,

hi
hello
bye
press any key to continue...

output after pressing the key,

welcome
once again
press any key to continue...

expected output after pressing the key,

Hi
Welcome
once again
press any key to continue...

mean , my need is not including Hi . My need is how to clear only above two lines, instead of clearing whole screen using cls..only hello and bye (above two lines) need to clear instead of clearing whole screen.

This is not orginal program it is just to explain and example to show u my concept and need. i hope i have make u understand my prblm.. Please help

1

There are 1 answers

0
AudioBubble On

Plain batch doesn't support this.

Except for the recent windows 10 versions which reintroduced Ansi Escape Sequences.
Kudos to Stephan for the link.

:: Q:\Test\2017\08\31\SO_45979664.cmd
:: 
@echo off
echo hi
echo hello
echo bye
pause
Echo esc[3Fesc[2Kesc[2Kwelcome
echo once again
pause

The esc in the above text has to be replaced by the Ctrl-Z Character (gets lost pasting here).

It depends on your editor how to input ESC / Ctrl-Z / 027 / 0x1b,
in Notepad++ for example Alt+027
in Textpad Ctrl+*(numpad),z

  • esc[3F goto first column, 3 lines up (including pause message)
  • esc[2K delete one line