1

I am logging a program (using the bash utility script) and I get outputs containing backspaces, where it was used, like: "5,^H ^H.6" instead of the final text: "5.6"

if I cat the log file I get the final "5.6", but if direct the result of cat into a file, and I open it with vi I still see "5,^H ^H.6"

Is there a way to save what I actually see using cat (make backspace really delete the character before)?

Many thanks in advance!

Michael M.
  • 10,486
  • 9
  • 18
  • 34
user2393987
  • 189
  • 1
  • 2
  • 9
  • With all the escape sequences, your question is more complex. Do you want to handle _only_ the backspace character, or do you want to handle _all_ ANSI escape sequences? In the first case, I think go with `sed`, in the second case, spawn a `tmux` terminal, execute `cat` in it, then save the terminal output to a file. – KamilCuk Jul 12 '22 at 10:06
  • 1
    check out https://stackoverflow.com/questions/6534556/how-to-remove-and-all-of-the-escape-sequences-in-a-file-using-linux-shell-sc – Ashok Jul 12 '22 at 10:59
  • Thanks for the quick reply! Using sed, I could handle other special characters like ^A, which appeared already ascii during typing. But when I type in the application that I am logging, backspace does not appear at all, it does delete back, as it should. It only appears in the log, but in return I cannot replace it with sed. Is it possible that it is some binary data, which is only translated to ^H ^H in vi? – user2393987 Jul 12 '22 at 11:04
  • `script` is a tool that can be invoked from any shell. The fact that you invoke it from `bash` does not make it a "bash program". – William Pursell Jul 12 '22 at 13:06

1 Answers1

0

Based on the answer of Ashok I have found the correct hex code for backspace: https://donsnotes.com/tech/charsets/ascii.html

sed 's/.\x08 \x08//g' log.out > log_without_backspaces.out

solved the problem, using just sed as KamilCuk suggested. Many thanks!

user2393987
  • 189
  • 1
  • 2
  • 9