Clear specific part of the screen

I want to clear specific part of the screen. Say for example , i am running a bash script

for i in {1..100}
do
echo "Current Record = $i"
done

if i use a clear command over there , it will clear my screen however when i scroll up i would have the old records , is there anyway in unix to just clear a single line everytime

Not sure what you want to achieve; if you want to output to a single line only, try adding a <carriage return> character:

$ for i in {1..10}; do echo -en "\rCurrent Record = $i"; sleep 1; done
1 Like

You could use this function where 'char="lots of spaces as required"', and, vert and horiz are the rows and columns of the terminal window where you want to over _write_...

Bazza...

You can overwrite the same line every time by printing a carriage return instead of a newline, the cursor will return to the beginning of the line but not travel down to the next line.

Note this does not clear the line per se, you would need to print blank spaces or use an escape sequence.

printf "Wait for it\r"
sleep 5
printf "Ding!          \r"

Things like setting up a scrolling region inside your terminal will also prevent scrollback but are not compatible with all terminals.

1 Like

Hi.

See also man tput ... cheers, drl

Thanks for your input guys.. This is what i was looking out for :slight_smile: