As article 51.5 explains, the files made by the script program can have stray control characters in them. The shell script called script.tidy can clean them up. Dan Bernstein wrote it and posted it to Usenet; I made a few changes. It reads from files or standard input; it writes to standard output.
script.tidy uses the substitute command to remove CTRL-m (RETURN) characters from the ends of lines. It uses the sed to repeat a series of commands that delete a character followed by CTRL-h (BACKSPACE). If you use DELETE as your , change the script to eat DELETE instead of BACKSPACE. script.tidy uses a with echo and tr to store the control characters in shell variables. Because the sed script has around it, the shell variables are substituted in the right places before the shell starts sed.
#!/bin/sh # Public domain. # Put CTRL-M in $m and CTRL-H in $b. # Change \010 to \177 if you use DEL for erasing. eval `echo m=M b=H | tr 'MH' '\015\010'` exec sed "s/$m\$// :x s/[^$b]$b// t x" $*
You can also hack the sed script in script.tidy to delete some of your terminal's 41.11 explains how to find these sequences. (A really automated script.tidy would read your termcap or terminfo entry and look for all those escape sequences in the script file.); article