Preserve colors with watch -n

1

I am running

watch tail -n 15     20151217.log

and my output looks like

12-17 04:42:52 DEBUG [31mXYZT    10  91.5[0m

Instead, I want to see it as colored text. What can I do?

I don't want to use simply tail -n, because it somehow skips lines and stalls.

Any ideas?

The Baron

Posted 2015-12-17T15:51:55.860

Reputation: 111

Also relevant: Many programs disable coloring (--color=auto or similar) when they detect output is being redirected. – Daniel B – 2015-12-17T22:23:12.630

Answers

0

The manual page for watch lists this option:

   -c, --color
          Interpret ANSI color and style sequences.

So you could change your command to

watch -c tail -n 15     20151217.log

and see the color as intended.

In preparing answer, I tested with Debian 7, which uses procps-ng. Scientific Linux uses an older version of procps (the set of programs containing watch). Debian uses the newer version cited in the manual page. For reference, Scientific Linux 6 uses the "latest" version from the SourceForge project which was forked several years ago here. The history for watch.c and watch.1 show that the color option was added in 2011 in procps-ng.

The older version from procps has no ability to filter escape sequences.

Thomas Dickey

Posted 2015-12-17T15:51:55.860

Reputation: 6 891

I have scientific linux.

watch --c tail -n 15 20151218.log watch: unrecognized option '--c' Usage: watch [-dhntv] [--differences[=cumulative]] [--help] [--interval=<n>] [--no-title] [--version] <command> – The Baron – 2015-12-18T14:54:01.407