0

For example, I run the top command and store it to a file in Linux, after that I open that file in Windows it contains some gibberish. Here is the file viewed in Notepad++:

File contents

The option to convert to UTF-8 in Notepad++ doesn't work.

How can I read that file in Windows? I tried using dos2unix but it doesn't work and gives the error:

dos2unix: Binary symbol 0x1B found at line 1

Edit: Trying the sed 's/\x1b\[[0-9;]*[a-zA-Z]//g' file.txt command gives the expected output but only in the terminal

Destroy666
  • 12,350

1 Answers1

2

These are ANSI escape sequences/codes, so basically ESC character followed by some other characters that are used as sequences to display colors, etc.

To remove them, you can for example use ansi2txt CLI tool, e.g.:

top | ansi2txt > output.txt

Here are also more ways to remove them: Removing ANSI color codes from text stream

Destroy666
  • 12,350