Qeebrato
Qeebrato

Reputation: 131

Introduce ANSI codes into a stream

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

Upvotes: 0

Views: 99

Answers (1)

hek2mgl
hek2mgl

Reputation: 158210

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

Upvotes: 1

Related Questions