Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

I hope this makes sense. I use 'scripts' to make copies of my ssh sessions for various reasons.

When I access the logs via less, etc, I see this:

Script started on Mon 12 Sep 2011 08:59:14 AM CDT

ESC]0;root@:~^G[root@ESC[1;31m ESC[0;0m~]# 
ESC]0;root@:~^G[root@ESC[1;31m ESC[0;0m~]# logout
ESC[HESC[2JConnection to closed.^M
Script started on Mon 12 Sep 2011 09:00:32 AM CDT
Last login: Sat Sep 10 18:13:00 2011 from ^M
ESC]0;root@:~^G[root@ESC[1;31m ESC[0;0m~]# 
ESC]0;     3.03, 2.32, 2.20^G
test.log (END) 

When I cat it, I see this:

Perk ~ # cat test.log 
Script started on Mon 12 Sep 2011 08:59:14 AM CDT

[root@ ~]# 
[root@ ~]# logout

Connection to closed.
Script started on Mon 12 Sep 2011 09:00:32 AM CDT
Last login: Sat Sep 10 18:13:00 2011 from 
[root@ ~]# [/code]

If I try and pipe this to a file, it returns to look like the less output.

When I edit it in vi, this is what i see:

Script started on Mon 12 Sep 2011 08:59:14 AM CDT
^M
^[]0;root@:~^G[root@^[[1;31m ^[[0;0m~]# ^M
^[]0;root@:~^G[root@^[[1;31m ^[[0;0m~]# logout^M
^[[H^[[2JConnection to closed.^M^M
Script started on Mon 12 Sep 2011 09:00:32 AM CDT
Last login: Sat Sep 10 18:13:00 2011 from ^M^M
^[]0;root@:~^G[root@^[[1;31m ^[[0;0m~]# ^M
^[]0;     3.03, 2.32, 2.20^G^M

Does anyone know how I can get this cat output into a file for easy viewing?

share|improve this question

migrated from stackoverflow.com Sep 15 '11 at 6:02

This question came from our site for professional and enthusiast programmers.

2  
It works properly with cat because your terminal emulator interprets these caracters as colors for the text. – Lynch Sep 15 '11 at 1:58
up vote 3 down vote accepted

Instead of regular less, try:

less -R
share|improve this answer

Why don't you use script

script -t scriptfile > timingsfile

So you can

replay scriptfile

The timing are optional. In fact you could run replay |ansifilter to translate into, say, HTML etc.

to have the exact script replayed in real-time. I think this is much more apt as clearly you are trying to log interactive sessions (most Unix tools are aware of when they are not connected to a tty (batch mode, piped stdin/out), and already prevent emitting terminal codes in such cases)


There is also termrec which is able to control the playback speed. Nice for creating specific screenshots e.g.

share|improve this answer
    
Your script ... > timingsfile should be script ... 2> timingsfile to capture stderr (the timing data output) in timingsfile, rather than stdout. Also, note that JPerkSter already is using script. – jwpat7 Sep 19 '11 at 19:11

There is a command colcrt which strips terminal formatting codes.

share|improve this answer

You must log in to answer this question.

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