how to keep the colored output of a command after piping it through grep

49 Views Asked by At

For the example, systemctl status weechat |grep Active

The output of systemd is green or red depending on status.

How to keep that when piping through grep (or other command like tail,...)?

There is --color, but it's not that.

.

1

There are 1 best solutions below

1
Philippe On BEST ANSWER

Use script to keep color :

script -qec "systemd status weechat" /dev/null |grep Active