1

Tail seems to parse TTY commands. When commands use ^M to erase the line & redraw the line in stdout, for example an animated ASCII progress bar.

When I tail a file where this is happening, I see the animated progress bar. I want to capture a single "frame" from tail & write it to another file.

Here's what I see when I view the file using tail 3%

Here's what I see with less or when I try to parse the log programmatically. ^M0%^M1%^M3%

I want to create a file that just contains "3%", or whatever the latest 'frame' of animation is. I want a command that captures what I as a human physically see on my screen, and writes it to a file.

For a bit of context - its for a web app. I want to have the browser poll for the latest status & replace the contents of a div to. I need a command that outputs the latest "frame" suitable for this use case.

Also an acceptable solution would be the stream the file live over websockets, and parse the file client side. Preferably though there exists some command or flag I can pass to tail to do this easily.

1 Answer 1

0

Have you thought about using redirects, you can take the STDOUT from a command and forward it to another file/terminal

so you can just redirect the output of tail like so - tail "file" > "anotherfile"

5
  • Yeah I tried that before posting, apologies for not clarifying. It redirects the control characters. It's the TTY that's parsing the control characters when I run tail (and I don't understand why the output from less differs). I need a program that replicates what the TTY/console is doing when I run tail. Simply redirecting the output of tail results in a file that differs from what I see in the TTY/console.
    – JoshRibs
    Aug 5, 2014 at 18:30
  • There is a perl one liner you can use perl -pi -e 'tr/\cM/\n/d; "filename" this basically does the same as dos2unix where it will replace all the ^M (carriage return in windows) with \n which is the carriage return in *nix so you could try tail "file" > "newfile"; perl -pi -e 'tr/\cM/\n/d;' "newfile"
    – Fegnoid
    Aug 6, 2014 at 7:38
  • But I don't just want to convert the ^M to newlines, I want it to "erase" the previous line like it does in a console.
    – JoshRibs
    Aug 7, 2014 at 22:38
  • ok, there is probably better ways of doing it but you can 0 byte the newfile before writing to it, the command would look like... > "newfile"; tail "file" > "newfile"; perl -pi -e 'tr/\cM/\n/d;' "newfile"
    – Fegnoid
    Aug 8, 2014 at 10:47
  • Not what I'm looking to do, thanks for trying to help though.
    – JoshRibs
    Aug 11, 2014 at 23:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .