Is there a tool to clean up the output of the script (1) tool?
script(1)
- a tool for recording an interactive terminal session; by default it writes to a file transcript
. My problem is that I am using ksh93
which has readline functions and so the transcript is flushed with all types of terminal escape sequences and it can be very difficult to recover the actually executed command. Not to mention stray ^M
and the like.
I am looking for a tool that will read a transcript file written script
, remove all junk and restore what the shell thinks was done, so I have something that shows $PS1
and the commands are actually executed. Otherwise, I'm looking for suggestions on how to write such a tool, ideally using knowledge from the terminfo database or not getting it, just using ANSI escape sequences.
Cheating that looks like in the history of the shell while it actually works would be acceptable as well.
a source to share
Does the cat or more work by default for viewing the transcript? Are you going to create a script from the commands actually executed (which in my experience can be dangerous)?
Anyway, 3 years with no answer, so I'll give him a shot with an incomplete solution. If you are only interested in the commands entered, remove the non-printable characters and then replace PS1 with something readable and unique and grep with that unique string. Like this:
$ sed -i 's/[^[:print:]]//g' transcript
$ sed 's/]0;cartman@southpark: ~cartman@southpark:~/CARTMAN/g' transcript | grep CARTMAN
Explanation: After the first sed PS1 'can be taken from one of the first few lines of the transcript file, and also - PS1' is different from PS1 - and can be modified with a unique readable line ("CARTMAN" here). Please note that the dollar sign at the end of the invitation has been deliberately omitted.
In a couple of examples I've tried, this didn't solve everything, but it did take care of most of the problems.
a source to share
This is essentially the same question asked recently in Can I programmatically "burn" ANSI control codes to a file using unix utils? - removing all non-printable characters will not fix
- built-in escape sequences
- backspace / overstriking for underline
- using refunds for forwarding
a source to share