I recorded my current session using the script
command, and all information was saved in a typescript
file, but when I opened it using Vim there were a lot of ^M
s due to carriage returns.
I tried to convert this file to the Unix format using the dos2unix
command, but I was unable to do so. It was giving this error:
dos2unix: Binary symbol 0x1B found at line 2,dos2unix: Skipping binary file typescript.
I was just curious why it is happening. Why does script
produce output in CR/LF
form and not simply in LF
form?
Best Answer
typescript
saves everything what is sent to your terminal which may include escape sequences for positioning, colors, brightness etc. (0x1B
is the ESC character.) The terminal output contains CR and LF even if the usual line ending in text files is different.The character
0x1B
makesdos2unix
assume your input might be a binary file. Because modifying a binary file might not be useful,dos2unix
rejects to do this by default. Apart from this there is no problem with the escape character.You can try
dos2unix -f
to force conversion of the seemingly binary file. This way you tell it that you know that modifying the line endings in this file is safe.Or use
vim
to remove the CR characters.:%s/
CTRL+V CTRL+M ENTERIn case there might be more than one CR per line
:%s/
CTRL+V CTRL+M//g
ENTER