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

  • 1
    The right way is to tell tools like top not to print these characters in the first place. Some tools modify their behavior automatically if their stdout is not a terminal. It seems top does not do this. Use -b, e.g. top -b -n 1 >output; see man 1 top. In general, if some troublesome_program provides no option to turn ANSI escape sequences off, you can try passing TERM=dumb in the environment, e.g. TERM=dumb troublesome_program. Apr 19 at 9:26

1 Answer 1


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

  • Thank you, that tool worked like a charm!
    – TeaViris
    Apr 19 at 18:01
  • @TeaViris No problem, make sure to mark answer as solution if it helped.
    – Destroy666
    Apr 21 at 14:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .