Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

3 Answers 3

up vote 2 down vote accepted

Instead of regular less, try:

less -R
share|improve this answer

There is a command colcrt which strips terminal formatting codes.

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

Your Answer

 
discard

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.