I am trying to make my bash (or tcl) script updates a line with three columns. After going back to the begin of the line I don't know how to move forward skipping some characters. I want to update specific information, not the whole line.
My script executes several instances of another script in parallel, which sends one among three types of messages (P1, P3 and P7). When a message is sent a column related to that type of message needs to be updated.

I want to print something like this with echo:
The number of the sent messages are:
P1: 2 P3: 1 P7: 5

The first line is static and the second is dynamic (the numbers in the second line need to be constantly updated) I can use '\b' or '\r' to move backward in the line without overwriting the characters. But how can I move forward in the line without overwriting the characters previously there? Is there some kind of "reverse" "\b"?

  • It may be easier to just update the entire line whenever new data comes (even with a way to move to a specific column, think of how to coordinate once the event count reaches 10 and the space allocated to that columns needs to grow).
    – dhag
    Sep 21, 2015 at 15:08
  • @dhag Each process don't know what is written in column of the other process (there are 3 process), that is why I don't rewrite the entire line.
    – NFTX
    Sep 21, 2015 at 17:29
  • @Anthon I think you are correct about my confusion. I have edited the question.
    – NFTX
    Sep 21, 2015 at 17:31

2 Answers 2


tput(1) may be suitable for this task:

#! /usr/bin/env bash

trap 'printf "\nbe seeing you\n"; exit' INT

printf "blah de blah\n"

while [[ 1 ]]; do
  tput cup 1 0

  x=$(( RANDOM % 42 ))
  y=$(( RANDOM / 42 ))
  z=$(( RANDOM * 42 ))

  printf "P1: %d P3: %d P7: %d\n" $x $y $z
  sleep 1
  • while [[ 1 ]]; do is overkill here. You wore out the keyboard 7 times where one keystroke is enough. while :; do.
    – ott--
    Sep 21, 2015 at 21:00

( this is bash )

printf "P1: 2 P3: 1 P7: 5\n"
printf "\033[2A\033[4C3\033[2B\r"

Will print P1: 2 P3: 1 P7: 5 and then change it to P1: 3 P3: 1 P7: 5.

General way of printing terminal escape codes is:


,where example CODEs are: A - Cursor Up, B - Cursor Down, and C - Cursor Forward

Here you have list of available Escape codes.

  • 2
    You can also use device independent instructions, such as tput cuu1 for cursor up, tput cud1 for down, and tput cuf1 for forward. See man 5 terminfo for details. Sep 21, 2015 at 15:30

Not the answer you're looking for? Browse other questions tagged .