-2

I have below command

command | sed 's/^/Progress: /g'

Output:

Progress: 1%
Progress: 2%
Progress: 3%
...
...
Progress: 100%

How can I limit that output to single line such that:

Progress: n%

Output should display only one line Progress: n% and n keeps progressively changes

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Haru Suzuki
  • 142
  • 10

2 Answers2

3
command|awk '{ printf "Progress: %s%%  \r", $1}'

This one is with ProgressBar

command|awk '{printf "\rProgress: " $1 "%% ["; for(c=0;c<$1;c++) printf "#"; printf "]" }'

Progress: 60% [############################################################]
ufopilot
  • 3,269
  • 2
  • 10
  • 12
1

Use \r to go to the beginning of the line without going to the next line.

command | while read -r percent; do
    printf 'Progress: %d%%  \r' "$percent"
done
printf '\n'
Barmar
  • 741,623
  • 53
  • 500
  • 612