如何在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'