5

Some programs makes beautiful progressbars and stuff using ANSI escape sequences. That's nice.

What's not nice though is that if i put the output of that kind of program into a file and then try to view it it's filled with strange escape sequences.

Is there a way to strip away all the ANSI codes while logging?

I usually log the output of a script this way:

./script >> /tmp/output.log
3
  • can't you just capture the output of the programs to separate log files. Put another way, why do you have to use script? Good luck!
    – shellter
    Commented Jun 10, 2011 at 13:30
  • The script is not a logging-script, the script/program is what uses the ANSI-sequences. It has normal output too and it's that normal output i wan't to store. The ansi-sequences should be stripped away.
    – Martin
    Commented Jun 10, 2011 at 14:33
  • This should be moved to unix.stackexchange.com. Commented Jun 10, 2011 at 14:36

2 Answers 2

7

Try:

$ TERM=dumb ./script >> /tmp/output.log

If that doesn't work, it's because the ANSI codes have been hard-coded into the script, so there is no easy way to remove them. If it does, it's because it's doing the right thing, delegating things like pretty output to libncurses or similar, so that when you change the TERM variable, the library no longer sends those codes.

0

use ansifilter:

$ ./script | ansifilter >> /tmp/output.log
2
  • 1
    Without more information, this is rather lackluster. Where would one obtain this software? Does it do anything more or different than the other answer here?
    – tripleee
    Commented Mar 2 at 7:00
  • 1
    The tool is included in various Linux distributions, for example Debian and Ubuntu (packages.debian.org/trixie/ansifilter). Some documentation reference might be helpful github.com/andre-simon/ansifilter
    – Orest Hera
    Commented Mar 4 at 7:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.