如何清除bash输出中的装饰颜色字符? [英] How to remove the decorate colors characters in bash output?
本文介绍了如何清除bash输出中的装饰颜色字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个控制台程序(translate-shell)有一个颜色输出,并为此使用特殊的装饰字符:^ [[22m,^ [[24m,^ [[1m ...等等。
$我尝试使用tr -d^ [[22m和带有sed的/ [\ ^ [[22m] // g',但只删除数字,而不是特殊字符^ [
谢谢。 / p>
解决方案
您有多种选择:
- https://unix.stackexchange.com / questions / 14684 / removal-control-chars-including-console-codes-colors-from-script-output
- http://www.commandlinefu.com/commands/view/3584/remove-color- code-special-characters-with-sed
- 和
-no-ansi
回答
EDIT
工作相当不错:
sed -rs / \x1B\ [([0-9] {1, 2}(; [0-9] {1,2})?)?[m | K] // g
A console program (translate-shell) has an output with colors and uses special decorate characters for this: ^[[22m, ^[[24m, ^[[1m... and so on.
I'd like to remove them to get a plain text.
I tried with tr -d "^[[22m" and with sed 's/[\^[[22m]//g', but only is removed the number, not the special character ^[
Thanks.
解决方案
You have multiple options:
- https://unix.stackexchange.com/questions/14684/removing-control-chars-including-console-codes-colours-from-script-output
- http://www.commandlinefu.com/commands/view/3584/remove-color-codes-special-characters-with-sed
- and as
-no-ansi
as pointed out by Jens in other answer
EDIT
This command does the job pretty well:
sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
这篇关于如何清除bash输出中的装饰颜色字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文