How to overwrite the previous print to stdout
The carriage return only returns to the start of the current line, so if your output is longer than a line, you'll only erase the last line. If this is enough of a problem that you need to control it, you can disable line wrapping to keep the cursor from wrapping to the next line.
The last occurrence of the delimiter "$" is removed from the "res" string using slicing. This is done by assigning the string "res" to a slice that excludes the last character of the string, which is the stray "$".
remove last STDOUT line in Python

There are two tricky lines: one disables the echo, the other one erases your password prompt remaining at the first position of the line. See similar questions with these tags.
Remove the Last Character From Each Line in Linux
Learn how to remove the last character from all lines in a file through examples

Furthermore, visual representations like the one above help us fully grasp the concept of Removed Last Output As Well.
output=$(head $file) keeps embedded newlines in the value of output , and trims all trailing newlines. It's how you reference the variable that makes the difference.
how do you delete previous outputs so you can replace them ...
Additional Notes on Removed Last Output As Well
Excel VBA to Remove Last Character from String (3 Examples) - Excel Insider. It gives the article a little more context before the image collection begins.
How to Remove Last Modified By in Excel (3 Ways) - ExcelDemy. It gives the article a little more context before the image collection begins.
Why is it whenever I do something like this, my last "output member. The extra context helps the page feel more useful without forcing the same phrase repeatedly.
Looking at multiple sources also helps separate the main idea from small decorative details.
These notes are added so the page offers more than images and gives each visitor a clearer reason to keep reading.