From: pshepher@loki.une.edu.au (Philip Shepherd)
Newsgroups: comp.unix.questions
Subject: Re: Utility to strip vt100 from script
Date: 12 Apr 92 00:16:45 GMT
Organization: University of New England - Northern Rivers (Lismore)

What follows is a summary of responses re my original posting:-
>
>Given a log-file of a session with an interactive program (i.e.
>by using "script" or similar) is there a method for translating
>this file into a text file suitable for editing.
>
>i.e. I use a VT100 terminal, so the log-file contains various control 
>character sequences required to produce pretty output on the screen.
>Obviously I can write a program for filtering out the unwanted
>characters but I'm reluctant to re-invent the wheel .... I also
>hoped that somebody may know of a utility which rather than just
>removing the control codes attempts to translate them in a rational manner.

I only received three replies (see below).  The first two methods boil
down to removing the control sequences using "sed".  The third method
relies on a utility called "screen" which I don't possess.

The problem with using "sed" is that although it removes the control
sequences the resulting file is not necessarily a good reproduction of
how things would have looked on the terminal.  I've hacked together some
code which makes more intelligent use of the control codes and produces
a much better end result.   If anybody is interested I may go to the 
extra effort of making my code more readable etc... and E-Mailing you a
copy,

Phil


*******************************************************************************
From: candle!root@gvls1.GVL.Unisys.COM (Bruce Momjian)
Organization: a consultant's basement
Date: 4 Apr 92 13:22:40 EST (Sat)

Try this:

cat my_script_file | sed -f /usr/lbin/bin/unesc.sed $*

where /usr/lbin/bin/unesc.sed is:

s/[ -/]*[0-Z\-~]//gp
s/[ -/]*\[[ -/]*[0-?]*[@-~]//gp

It was posted about 3 weeks ago.  Works well.

--
Bruce Momjian           | 830 Blythe Avenue               | home: (215)853-3000
root%candle.uucp@ls.com | Drexel Hill, Pennsylvania 19026 | work: (215)353-9879
*******************************************************************************

*******************************************************************************
From: alan@edstar.gse.ucsb.edu (Alan Moses)
Date: Tue, 31 Mar 92 18:08:02 PST

Hi Phil - 

Here's what I use to clean up a script session.  This csh script
runs script's output into a temp file and then cleans it up. No
translating - just stripping out the junk.  It seems to work 
just fine for me, but I must admit I spent little time testing 
and no time optimizing.  I'm open to suggestions for improvements, 
and I look forward to seeing what else you come up with in your 
summary follow-up.

- Alan

Alan Moses
Graduate School of Education		alan@edstar.gse.ucsb.edu
UC Santa Barbara   			UCSB PROFS: AMOSES 
Santa Barbara, CA 93106-9490  		Voice: (805) 893-8031

----------------------------------------------------------------
The main routine, which I call 'record'.
----------------------------------------------------------------
#! /bin/csh -f
###############################
#	record
#	sets up a script session; then
#	on exit strips undesirable
#	characters (Ctrl chars and vt100
#	escape sequences).
###############################
#
onintr catch
#
set tmp = /tmp/$$.record
#
if ($#argv == 0) then
	echo ""
	echo "Usage: record filename"
	echo "The output filename must be supplied."
	echo ""
	exit 1 
else
	set outfile = $argv[1]
	set spstring = `echo $outfile|awk '{ L = length($0); for (i=1; i<= 17 - L; i++) blanks = blanks "."; print blanks}'`
	echo "+-----------------------------------------------+"
	echo "| Everything that follows on the screen will be |"
	echo -n "| captured into a file named $outfile."
	echo "${spstring} |"
	echo "| Type 'exit' to stop capturing session.        |"
	echo "+-----------------------------------------------+"
endif
#
# test for existing file
if (-e $outfile) then
	echo "A file named $outfile already exists."
	echo "Press O to overwrite, A to append, or C to cancel."
	stty raw -echo
	set answ = `/usr/local/bin/getch`
	stty -raw echo
	echo ""
	switch ($answ)
		case [oO] :
			#overwrite 
			set aflag = 0
			breaksw
		case [aA] :
			#append
			set aflag = 1
			breaksw
		default:
			#any other response cancels
			clear
			exit 1
			breaksw
	endsw
endif
# record all output into temp file
script $tmp
#
# Remove carriage returns and backspace sequences 
if ($aflag == 1) then
tr -d '\015' < $tmp | sed -f /usr/local/bin/remove-ansi.sed >> $outfile
else
tr -d '\015' < $tmp | sed -f /usr/local/bin/remove-ansi.sed > $outfile
endif
exit 0
#
catch:
	/bin/rm -f $tmp
	exit 1
----------------------------------------------------------------
Now the sed commands to do the work (in remove-ansi.sed)
Note the escapes: ^[ 
----------------------------------------------------------------
s/[ -/]*[0-Z\-~]//gp
s/[ -/]*\[[ -/]*[0-?]*[@-~]//gp
*******************************************************************************

******************************************************************************
From: steimann@exquando.quantum.de (Ulrich Steimann)
Date: Wed, 1 Apr 92 16:04:09 +0200
Organization: Quantum Software GmbH, Dortmund, Germany


My usual method is to use "screen". If you have it too, I would
suggest to write a small filter named slow, which reads n chars,
writes n chars and sleeps 1 second.

I start screen, type 'slow < typescript' and press CTRL-A CTRL-H to
make a hardcopy of the screen.

That's my easiest way for making hardcopies for a mask-system.

Greetings,
	  Ulrich

Ulrich Steimann, Quantum GmbH, D-4600 Dortmund    email: steimann@quantum.de
FAX: 0231-75441-115   Diese Signatur ist gleichberechtigt im Sinne der Bits:
Sie enthaelt 1180 '0' und 1180 '1'.   Es folgen die Quotenbits:
------________________________________________________________________------
*******************************************************************************
-- 
Philip 	Shepherd                      Internet: pshepher@loki.une.oz.au
University of NewEngland
Northern Rivers
Lismore NSW Australia
Newsgroups: comp.unix.questions