0

I want any stdout to display on one line only. Each successive line should overwrite the last.

Typically, I would do

echo -ne "Overwrite me. \033[0K\r"

But now I want to pipe the output, and since echo is not a filter I need to use sed or something e.g.

cat story.txt | some.sed.like.util.for.replacing.$.with.\033[0K\r
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
Qeebrato
  • 131
  • 7
  • Possible duplicate of [How to delete and replace last line in the terminal using bash?](https://stackoverflow.com/questions/2388090/how-to-delete-and-replace-last-line-in-the-terminal-using-bash) – hek2mgl Aug 04 '17 at 09:38

1 Answers1

1

sed can't be used since sed will always append a newline to it's output. You need to use a while loop in the shell:

while read -r line ; do
    echo -en "\r\033[0K${line}"
    sleep 1
done < story.txt
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • 1
    `echo -en "\r\033[0K${line}"` — otherwise the longest line so far is always displayed "under" the current line. – gboffi Aug 04 '17 at 09:58