1

My question is how would I hide all text above the last line?
Somehow delete the text of the first part and then only show an echo of the last line - that still has user input functionality though.

[=  ]
[== ]
[===]
"last line with any text" (Y/N)?

Is there any rule I could add to a batch command that would show only the last line of the current command text result in the window?

  • This seems to be an XY problem, you want to hide all text then why you will display them using echo? – Wasif Hasan Aug 6 at 1:02
  • Ok, my first example was a bit misleading and I removed it. My question is just about how to hide everything that is not the last line. – atereou Aug 6 at 1:12
  • Then append >nul 2>&1 to each echo lines you want to hide. – Wasif Hasan Aug 6 at 1:53
  • you probably asking for ANSI escape sequences cursor movement how to erase line – alecxs Aug 6 at 4:38
  • 3
    You posted this exact question on StackOverflow. – Gerhard Aug 7 at 7:29
1

Don't use cmd and use powershell instead. Get-Content cmdlet (and its aliases cat and gc) has a Tail option to do this

Get-Content file_path -Tail 1

If the text is the result of another command then use Select-Object or its select alias

your_command | Select-Object -Last 1

If you really need to use cmd then run the command from PowerShell like this

powershell -Com "gc file_path -Tail 1"
powershell -Com "your_command | select -Last 1"

If you have some kind of POSIX environments on your system wsl/wsl2 or cygwin then just use tail:

cat file | tail -n 1
your_command | tail -n 1
tail file -n 1

See also

| improve this answer | |
0
  • To delete/remove used lines you can use the solution from @LotPings in this answer, in additional, you also can use this in base64 decoded by Certutil
@echo off 

title <nul && title Q1575583

call %:^0 && setlocal EnableDelayedExpansion

for /L %%L in (1 1 4)do echo\Line 0%%L

%__APPDIR__%timeout.exe -1 >nul 
type "%temp%\_bs.bin" 
type "%temp%\_bs.bin" 

%__APPDIR__%timeout.exe -1 >nul 
echo/Line 06

%__APPDIR__%timeout.exe -1 >nul 
type "%temp%\_bs.bin" 

%__APPDIR__%timeout.exe -1 >nul 
echo/Line 07

%__APPDIR__%timeout.exe -1 >nul 
type "%temp%\_bs.bin" 

%__APPDIR__%timeout.exe -1 >nul
type "%temp%\_bs.bin" 

2>nul del/Q /F "%temp%\_bs.bin" 
endlocal & goto=:EOF

%:^0
>nul 2>&1 del /q /f "%temp%\_bs.bin"
>nul 2>&1 "%__APPDIR__%Certutil.exe" -decode -f "%~f0" "%temp%\_bs.bin" & exit /b
:: <-----BEGIN .\_bs.bin ----- G1sxRhtbMEobWzFGG1swSg0K== -----END .\_bs.bin -----> ::
  • Outputs:

enter image description here

  • About the strings in Base64 in this bat/cmd decoded in file "%temp%\_bs.bin"

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.