1

script(1) is a tool for keeping a record of an interactive terminal session; by default it writes to the file transcript. My problem is that I use ksh93, which has readline features, and so the transcript is mucked up with all sorts of terminal escape sequences and it can be very difficult to reconstruct the command that was actually executed. Not to mention the stray ^M's and the like.

I'm looking for a tool that will read a transcript file written by script, remove all the junk, and reconstruct what the shell thought it was executing, so I have something that shows $PS1 and the commands actually executed. Failing that, I'm looking for suggestions on how to write such a tool, ideally using knowledge from the terminfo database, or failing that, just using ANSI escape sequences.

A cheat that looks in shell history, as long as it really really works, would also be acceptable.

Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533

2 Answers2

0

Doesn't cat/more work by default for browsing the transcript? Do you intend to create a script out of the commands actually executed (which in my experience can be dangerous)?

Anyway, 3 years without an answer, so I will give it a shot with an incomplete solution. If your are only interested in the commands actually typed, remove the non-printable characters, then replace PS1' with something readable and unique, and grep for 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 first sed, PS1' can be taken from one of the first few lines of the transcript file, as is -- PS1' is different from PS1 -- and can be modified with a unique readable string ("CARTMAN" here). Note that the dollar sign at the end of the prompt was left out intentionally.

In the few examples that I tried, this didn't solve everything but took care of most issues.

bsravanin
  • 1,803
  • 1
  • 14
  • 15
0

This is essentially the same question asked recently in Can I programmatically “burn in” ANSI control codes to a file using unix utils? -- removing all nonprinting characters will not fix

  • embedded escape sequences
  • backspace/overstriking for underlining
  • use of carriage-returns for overstriking
Community
  • 1
  • 1
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105