Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »

Review Suggested Edit

You can't approve or reject suggested edits because you haven't yet earned the Edit Posts ability.

Approved.
This suggested edit was approved and applied to the post 7 months ago by alx‭.

0 / 255
  • 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?

Suggested 7 months ago by matthewsnyder‭