为Bash Shell命令的多行输出中的多个字符串着色

时间:2019-02-02 00:58:59

标签: linux shell

如何在shell命令的多行输出中使用一种颜色特定的字符串?

例如,warning可以是yellow,而errors or error可以是red

输出包含以下几行。

- warning - LINE:129 W0511:TODO: Encountered errors nhandled exception raised: <NoSuchElementException> Message:
- warning - LINE:199 W0511:TODO: [2] Updated/add code based on the implementation from TODO # [1]
- warning - LINE:203 W0511:TODO: [3] Updated/add code based on the implementation from TODO # [1]
- warning - LINE:207 W0511:TODO: [4] Updated/add code based on the implementation from TODO # [1]

我尝试过了。适用于所有3个字符串的一种颜色red。是否可以为warning分配不同的颜色?

echo "$output" | egrep -n --color=always 'warning|error|errors'

0 个答案:

没有答案