I want to implement a progress bar showing elapsed seconds in bash. For this, I need to erase the last line shown on the screen (command \"clear\" erases all the screen, but
In case the progress output is multi line, or the script would have already printed the new line character, you can jump lines up with something like:
printf "\033[5A"
which will make the cursor to jump 5 lines up. Then you can overwrite whatever you need.
If that wouldn't work you could try printf "\e[5A" or echo -e "\033[5A", which should have the same effect.
Basically, with escape sequences you can control almost everything in the screen.