Post History
I wrote a filter program to overwrite each line with the next one. $ cat /usr/local/bin/ovr #!/bin/sh sed '2,$s/^/\x1B[1A\x1B[K/'; Here's the behavior: $ echo | ovr $ echo 'foo' | ovr ...
Question
terminal
#3: Post edited
How to overwrite each line with the next one?
- How to overwrite each line of STDOUT with the next one?
I wrote a filter program to overwrite each line with the next one. ```sh $ cat /usr/local/bin/ovr #!/bin/sh sed '2,$s/^/\x1B[1A\x1B[K/'; ``` Here's the behavior: ```sh $ echo | ovr $ echo 'foo' | ovr foo $ echo -e 'foo\nbar' | ovr bar $ echo -e 'foo\nbar\nbaz' | ovr baz $ echo -e 'foo\nbar\nbaz' | ovr | wc -l 3 ``` It is useful for example when compiling a large program, where you might not want to pollute your screen with so many lines. For example, in build systems like the Linux kerenl one, for each file that's compiled, one line goes to stdout, of the form ` CC some/file.o`. I usually compile it with `make -j24 | ts -s`, to know for how long it's been running, from which I can guess how much is remaining. But I don't really need to see all lines; just the last one. So I do the following. ```sh $ time make -j24 | ts -s | ovr 00:00:04 CC drivers/pinctrl/intel/pinctrl-sunrisepoint.o ``` The line will be updating all the time. This program has a some flaw, which I'd like to fix. If the line is long (longer than the terminal width), the overwriting doesn't work well, and only overwrites the part of the lines that has been written in the last "visual" line in the terminal. For an 80-col terminal, this is an example: ```sh $ echo -e '123456789q123456789w123456789e123456789r123456789t123456789y123456789u123456789i123456789o\nfoo' | ovr 123456789q123456789w123456789e123456789r123456789t123456789y123456789u123456789ifoo ``` How can this bug be fixed? Is it possible to fix it?
#2: Post edited
- I wrote a filter program to overwrite each line with the next one.
- ```sh
- $ cat /usr/local/bin/ovr
- #!/bin/sh
- sed '2,$s/^/\x1B[1A\x1B[K/';
- ```
- Here's the behavior:
- ```sh
- $ echo | ovr
- $ echo 'foo' | ovr
- foo
- $ echo -e 'foo\nbar' | ovr
- bar
- $ echo -e 'foo\nbar\nbaz' | ovr
- baz
- $ echo -e 'foo\nbar\nbaz' | ovr | wc -l
- 3
- ```
- It is useful for example when compiling a large program, where you might not want to pollute your screen with so many lines. For example, in build systems like the Linux kerenl one, for each file that's compiled, one line goes to stdout, of the form ` CC some/file.o`.
- I usually compile it with `make -j24 | ts -s`, to know for how long it's been running, from which I can guess how much is remaining. But I don't really need to see all lines; just the last one. So I do the following.
- ```sh
- $ time make -j24 | ts -s | ovr
- 00:00:04 CC drivers/pinctrl/intel/pinctrl-sunrisepoint.o
- ```
- The line will be updating all the time.
This program has a some flaws, which I'd like to fix.1:- If the line is long (longer than the terminal width), the overwriting doesn't work well, and only overwrites the part of the lines that has been written in the last "visual" line in the terminal.
- For an 80-col terminal, this is an example:
- ```sh
- $ echo -e '123456789q123456789w123456789e123456789r123456789t123456789y123456789u123456789i123456789o\nfoo' | ovr
- 123456789q123456789w123456789e123456789r123456789t123456789y123456789u123456789ifoo
- ```
- How can this bug be fixed? Is it possible to fix it?
- I wrote a filter program to overwrite each line with the next one.
- ```sh
- $ cat /usr/local/bin/ovr
- #!/bin/sh
- sed '2,$s/^/\x1B[1A\x1B[K/';
- ```
- Here's the behavior:
- ```sh
- $ echo | ovr
- $ echo 'foo' | ovr
- foo
- $ echo -e 'foo\nbar' | ovr
- bar
- $ echo -e 'foo\nbar\nbaz' | ovr
- baz
- $ echo -e 'foo\nbar\nbaz' | ovr | wc -l
- 3
- ```
- It is useful for example when compiling a large program, where you might not want to pollute your screen with so many lines. For example, in build systems like the Linux kerenl one, for each file that's compiled, one line goes to stdout, of the form ` CC some/file.o`.
- I usually compile it with `make -j24 | ts -s`, to know for how long it's been running, from which I can guess how much is remaining. But I don't really need to see all lines; just the last one. So I do the following.
- ```sh
- $ time make -j24 | ts -s | ovr
- 00:00:04 CC drivers/pinctrl/intel/pinctrl-sunrisepoint.o
- ```
- The line will be updating all the time.
- This program has a some flaw, which I'd like to fix.
- If the line is long (longer than the terminal width), the overwriting doesn't work well, and only overwrites the part of the lines that has been written in the last "visual" line in the terminal.
- For an 80-col terminal, this is an example:
- ```sh
- $ echo -e '123456789q123456789w123456789e123456789r123456789t123456789y123456789u123456789i123456789o\nfoo' | ovr
- 123456789q123456789w123456789e123456789r123456789t123456789y123456789u123456789ifoo
- ```
- How can this bug be fixed? Is it possible to fix it?
#1: Initial revision
How to overwrite each line with the next one?
I wrote a filter program to overwrite each line with the next one. ```sh $ cat /usr/local/bin/ovr #!/bin/sh sed '2,$s/^/\x1B[1A\x1B[K/'; ``` Here's the behavior: ```sh $ echo | ovr $ echo 'foo' | ovr foo $ echo -e 'foo\nbar' | ovr bar $ echo -e 'foo\nbar\nbaz' | ovr baz $ echo -e 'foo\nbar\nbaz' | ovr | wc -l 3 ``` It is useful for example when compiling a large program, where you might not want to pollute your screen with so many lines. For example, in build systems like the Linux kerenl one, for each file that's compiled, one line goes to stdout, of the form ` CC some/file.o`. I usually compile it with `make -j24 | ts -s`, to know for how long it's been running, from which I can guess how much is remaining. But I don't really need to see all lines; just the last one. So I do the following. ```sh $ time make -j24 | ts -s | ovr 00:00:04 CC drivers/pinctrl/intel/pinctrl-sunrisepoint.o ``` The line will be updating all the time. This program has a some flaws, which I'd like to fix. 1: If the line is long (longer than the terminal width), the overwriting doesn't work well, and only overwrites the part of the lines that has been written in the last "visual" line in the terminal. For an 80-col terminal, this is an example: ```sh $ echo -e '123456789q123456789w123456789e123456789r123456789t123456789y123456789u123456789i123456789o\nfoo' | ovr 123456789q123456789w123456789e123456789r123456789t123456789y123456789u123456789ifoo ``` How can this bug be fixed? Is it possible to fix it?