Removing the escape characters from GNU Screen's screenlog.%n
Solution 1
Try this piece of Perl magic:
perl -ne 's/\x1b[[()=][;?0-9]*[0-9A-Za-z]?//g;s/\r//g;s/\007//g;print' < screenlog.0
Solution 2
Also try the -r or -R option of less.
less -r screenlog.0
Solution 3
Use ansifilter.
ansifilter screenlog.txt > screenlog.txt.clean
Solution 4
Once you capture your session in screenlog.n , you can cat the file to the terminal and then use screen's hardcopy command to dump the cat's output to a file . The result will provide you with clean output that does not have any escape sequences.
The only 'gotcha' seems to be to make sure that hardcopy captures eveyrthing in the scrollback buffer and that the scrollback buffer contains only what you want to capture.
1. $ screen
2. $ cd /path/to/screenlog.n directory/
3. $ wc -l screenlog.n
4. $ screen -X scrollback 245 # 245 is the number of lines found from your wc command + 5
5. $ cat screenlog.n
6. $ screen -X hardcopy -h screenlog.n.cleaned
Note that -h ensures that you capture the entire scrollback history and not just whats in immediate view
The screenlog.n.cleaned file will now contain a hardcopy of the cat output and won't include any escape sequences
Solution 5
I use the strings
command to make a screen log readable. Under Debian it is part of the binutils package.
As its man page says:
strings - find the printable strings in a object, or other binary, file
Related videos on Youtube
shaond
Co-founder of NewsMaven Pty Ltd (newsmaven.co). A technology company that builds software solutions for the Publishing industry.
Updated on September 17, 2022Comments
-
shaond over 1 year
Is it possible to remove the ESC sequences in GNU Screen's output file? Things such as colours, tabs and other escape characters make their way into the log files and become difficult to decipher.
I've tried Dr. Google & Co. as well as reading the manual, but haven't been able to find anything suitable...
Perhaps I've overlooked something?
-
shaond over 14 yearsThanks for that - that's AWESOME! It still has the ^G and ^M characters in there, but its a lot more readable...
-
whitequark over 14 yearsAdded that to the expression.
-
John T about 14 yearsI wonder how many ASCII faces are in that one liner. I stopped counting around 20.
-
whitequark about 14 yearsOf course I can write another one-liner that will count them.
-
Thalys almost 12 yearsis that something in every linux system or something that needs to be installed?
-
Simon Sheehan almost 12 years@JourneymanGeek it's not even in the Ubuntu repos, so I'd say its not exactly popular. Looks like you have to get it yourself from the project page, and run/compile yourself. Wouldnt exactly call it a popular program ansifilter.sourceforge.net
-
thekingoftruth over 11 yearsI'm on OSX and used
brew install ansifilter
and it worked like a charm. -
dmh almost 9 yearsI don't know how this has changed since the 2012 comments about distribution, but I found this in the repo for the current release of Fedora (22).