6

I want to store a colored terminal output to a file (maybe a .rtf or whatever). In OSX I am able to manually copy it and paste it in a .rft file using Textedit, however I wanted to store it automatically using something like:

command &> somefile.rtf

Storing the output in a .txt preserves the color tags but they are useless since they can only be seen from the terminal (using cat).

Is there a way to do that?

I read a similiar question but it didn't solve the issue of storing the output in a file format that supports colors (and can be opened without a terminal).

4
  • In what way(s) did the other question/answers not "solve it" for you? What happened when you tried those suggestion solutions? Commented Jun 17, 2014 at 20:08
  • 1
    have a look at this question stackoverflow.com/questions/245121/… - in the comments on aha c program it says '(...) compiles and runs without problem on os x'
    – wmz
    Commented Jun 17, 2014 at 20:12
  • It is just solving the issue of not removing the color tags using grep. I need to store the colored output in a file that can be opened without using a terminal (a .doc, .rtf, .ods, etc.) [I edited my question] Commented Jun 17, 2014 at 20:18
  • In case you still need it, you can pass through the html format (then you can convert to whatever else). There is a script v0.23 or the older v 0.15, that you can use so command | ansi2html.sh > file.html.
    – Hastur
    Commented Jun 22, 2016 at 13:25

1 Answer 1

4

Since the colours are stored with their ansi sequence you can create a script to translate each of them... or you can use a script just made.

For example it exists the script ansi2html [v0.15,v0.23] that you can make executable, put in a directory of your path (typically ~/bin) and use with

command | ansi2html.sh > file.html

Then if you need a different format you can convert it or you can rewrite the script.

Note that some commands know if their output is piped or not.
For example, ls may change its output if piped.

You must log in to answer this question.

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