2

I am redirecting the output of the terminal to a file using:

Command > File.txt

but the contents of the file appear like this:

enter image description here

What is the problem? How can I make them appear normal?

muru
  • 193,181
  • 53
  • 473
  • 722
Adam
  • 2,578
  • 5
  • 25
  • 43
  • The command might be colouring its output. Which command is it? – muru Apr 12 '17 at 04:17
  • The command is minicom. – Adam Apr 12 '17 at 04:20
  • According to [this](http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Functions-using-CSI-_-ordered-by-the-final-character_s_), that's the sequence to set the cursor row and column to (23,80) and (24,17). Not sure why it is printing that, though. – muru Apr 12 '17 at 04:28
  • In general, see http://unix.stackexchange.com/q/14684/70524 for a robust way of removing xterm control sequences from output. I think there should be way to convince minicom to avoid outputing these, but I don't know. – muru Apr 12 '17 at 05:14

3 Answers3

3

The command you're executing (minicom) is using "VT100 Escape Sequences" to do cursor positioning.

To remove the characters listed above, pipe the file through

sed -e 's/^[\[[0-9][0-9];[0-9][0-9]H//'
#         ^^ actual ESCape

I got the Escape by typing Ctrl-VEsc.

waltinator
  • 35,099
  • 19
  • 57
  • 93
1

Those are terminal escape sequences, to be interpreted by the terminal driver. As the output from the program is being saved to a file, the (minicom) program rather erroneously dumping the escape sequences too without checking where it's STDOUT is going.

To get rid of the escape sequences, using sed to remove the lines that contain 23;80H, dry-run:

sed '/23;80H/d' file.txt

Modification:

sed -i '/23;80H/d' file.txt

If you wish to keep a backup with an extension e.g. .bak, do:

sed -i.bak '/23;80H/d' file.txt
heemayl
  • 90,425
  • 20
  • 200
  • 267
0

This happens because you haven't set character encoding of output file to UTF-8.

In case you cannot change /etc/* files,

you can manually set the gnome-terminal menu Terminal|Set Character Encoding to Unicode(Utf-8)

Answer obtained from this stackoverflow link

Piyush Patel
  • 111
  • 3