Search code examples
bashcolorsgreppipe

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


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.

.


Solution

  • Use script to keep color :

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