51.6 Cleaning script FilesAs 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 sed ( 34.24 ) substitute command to remove CTRL-m (RETURN) characters from the ends of lines. It uses the sed test command ( 34.20 ) to repeat a series of commands that delete a character followed by CTRL-h (BACKSPACE). If you use DELETE as your erase character ( 5.9 ) , change the script to eat DELETE instead of BACKSPACE. script.tidy uses a trick ( 45.35 ) with echo and tr to store the control characters in shell variables. Because the sed script has doublequotes ( 8.14 ) around it, the shell variables are substituted in the right places before the shell starts sed .
You can also hack the sed script in script.tidy to delete some of your terminal's escape sequences ( 5.8 ) ; article 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.) - |
|