0

my friend is creating mplayer server on Raspberry PI and is currently trying to check screenlog for current time. The problem starts with getting the last line. Doesn't matter if we use tail, awk, read or anything else, the console output is always breaking lines and refreshing (sortof). Using cat also doesn't output whole file, but line by line removing the previous one. MPlayer add's '\033[K' to all lines, and it appears there's no way of removing it by sed, or defining other IFS.

Here are some outputs:

[bot@aurora ~]$ tail -n 1 screenlog.0
A: 00:00:57 / 00:04:19 (21%) Cache: 45%[bot@aurora ~]$
[bot@aurora ~]$ tail -n 1 screenlog.0 | awk {'print $2'}
00:00:00


[bot@aurora ~]$ awk '/./{line=$0} END{print line}' screenlog.0
A: 00:00:57 / 00:04:19 (21%) Cache: 45%
[bot@aurora ~]$ awk '/./{line=$0} END{print line}' screenlog.0 | awk {'print $2'}
00:00:00

Here's the screenlog : http://sejbr.max-play.pl/screenlog.0

SEJBR
  • 348
  • 8
  • 15
  • 1
    Please show what you have done with sed. Set up small test case like `printf "[Kabc\nlmn[Kopq\nxyz[K\nend\n" | sed 's/[K//'` and show us what your getting. The `` is just a place holder token of course, in vi(m), you need to do Ctrl-V to get a true char (which will appear as `^[`). Maybe that's your problem? Good luck. – shellter Jun 18 '14 at 01:58
  • @shellter This is what vim shows `^[[0m^[[0mA: 00:00:00 / 00:04:19 (0%) Cache: 86%^[[K^M^[[0m^[[0mA: 00:00:00 / 00:04:19 (0%) Cache: 86%^[[K^M^`. Still seding it out doesn't seem to be working and behaves the same. I've tried `'s/^[K//'` which gave me expression error so i escaped the special characters (`'s/\^\[K//'`). I also tried `sed "s,\x1B\[[0-9;]*[a-zA-Z],,g"` from other website, which in theory should remove everything but alnum. The problem is still the same. – SEJBR Jun 18 '14 at 14:52
  • Editing anything in the file and saving it again with sublimetext3 seems to fix the problem. Special characters are still in the file visible throu vim, but it doesn't appear to act so strangely as before. So is it a problem with file format or something when saved oryginaly by screen from mkplayer? Also as resaved files work correctly, the screenlog from the question itself will work ok.. – SEJBR Jun 18 '14 at 15:23
  • 1
    Ok, hard to decide where to act. If you can **edit your question** to include 2 lines of sample data, OR at least expected output from the first 2 lines of your posted screenlog.0, maybe we can help. (However I don't see any `^[` chars). Also re-read my initial comment. The key point there is that what appears on the screen as 2 chars, '^[` is actually 1 character, the `` char. From your responses above its not clear that you see the difference. (I am likely wrong about that ;-) .. Good luck! – shellter Jun 18 '14 at 16:02
  • 1
    This sort of thing is at the outerlimits of `sed`s abilities, and is for advanced users. I believe it can be done, (I'm almost sure at an old job I have done this (but don't have the code anymore) ), so you just have to keep plugging away at it. Hence making smaller test cases to get one thing working, then add more. To reiterate, `^[` is one char, followed by `[` which is another char, followed by `0m` are 2 more chars. Good luck. – shellter Jun 18 '14 at 16:05

2 Answers2

1

pipe mplayer's output through 'strings', like so:

mplayer file | strings >screenlog.0
Mike
  • 2,393
  • 3
  • 25
  • 37
  • mpv https://www.youtube.com/watch?v=zZiYFFDGoh0 -no-video | strings > dev.log Generates empty dev.log file. – SEJBR Jun 17 '14 at 19:07
0

My friend came up with a solution. The easiest way is to use something outside bash, like PHP.

$data = file_get_contents('/tmp/mplayer');
$data = preg_replace('/\<ESC>\[K/' , "\n", $data);
echo $data;

Well that was pretty simple in a way :P.

Thank you all for responding.

SEJBR
  • 348
  • 8
  • 15