I used the script program to record an interactive session:
$ script
$ echo<-<-<-<-printf "hello\n"
$ exit
The sequence <- is representing the backspace character.
I want the following as output:
$ printf "hello\n"
$ exit
But the actual result contains all individual keystrokes (looking with cat --show-nonprinting).
I tried reading line-by-line with the read command. It does edit out the backspaces, but it also removes the command prompt, and it seems it converts \n into n.
I'm looking for a way to have the text the user was seeing on screen (command prompt, edited input and command output -- colors don't matter).
For reference a sample output:
^[[?2004l^M^[[?2004h$ echo^H^[[K^H^[[K^H^[[K^H^[[Kprintf "hello\n"^M
^[[?2004l^Mhello^M
^[[?2004h$ exit^M
^[[?2004l^Mexit^M
IIUC, ansi2txt [1] will do exactly what you want:
$ ansi2txt typescript > ANSI2TXT
$ cat ANSI2TXT
$ printf "hello\n"
hello
$ exit
Script done on Wed 15 Apr 2020 07:48:55 PM CEST
[1] https://sourceforge.net/projects/ansi2txt
scriptreplayhelp? Those strings (ESC [ digits ; digits m) are "VT100 Control Sequences", and are influenced by the$TERMenvironment variable. I've used an Emacs function to eliminate them from myscriptlogs, but suggesting "Learn Emacs" is extreme overkill. - waltinator^M(0x0D, <CR>),^H(0x08, <BS>), and^[(0x1B; <ESC>). Why not start debugging with simpler, straight forward examples? And, why wouldn'tcat file | while read -r ...work? - RudiC