Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 6 down vote accepted

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
share|improve this answer
Thanks for that - that's AWESOME! It still has the ^G and ^M characters in there, but its a lot more readable... – shaond Jan 22 '10 at 12:55
Added that to the expression. – whitequark Jan 22 '10 at 13:10
I wonder how many ASCII faces are in that one liner. I stopped counting around 20. – John T Feb 1 '10 at 5:19
Of course I can write another one-liner that will count them. – whitequark Feb 1 '10 at 5:30

Use ansifilter.

ansifilter screenlog.txt > screenlog.txt.clean
share|improve this answer
is that something in every linux system or something that needs to be installed? – Journeyman Geek Jul 15 '12 at 14:37
@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 – Simon Sheehan Jul 16 '12 at 2:49
I'm on OSX and used brew install ansifilter and it worked like a charm. – thekingoftruth Oct 16 '12 at 17:56
I 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). – dmh Jun 11 '15 at 10:25

Also try the -r or -R option of less.

less -r screenlog.0
share|improve this answer
Nice solution. It deals with all the ^H (delete) characters properly, displays progress bars without the ^M cruft, and even preserves my color prompt! Of course, sometimes displaying a log isn't sufficient. – Quantum7 Mar 28 '13 at 21:44

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

share|improve this answer
Very very neat. All other perl/sed/python one-liner failed for me. Very frustrating when thinking that less -r/more were handling my file directly. One suggestion wc -l did not work for me. It returned 28226, but really needed 33031 in my case. – malat Mar 19 '14 at 12:08

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

share|improve this answer

If you are screen user then the screen hardcopy solution suggested by Joel Verks' post will work best -- assuming that you have a large scrollback defined in your .screenrc:

defscrollback 10000

then you'd do:

  1. Display your screenlog file:

    $ cat screenlog.<screen_window_num>
  2. Use hardcopy -h (see screen man page) to save the current window content and its scrollback buffer into the hardcopy.# file:

    <Escape key> (Ctrl-a by default)
    :hardcopy -h
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.