如何删除bash输出中的装饰颜色字符? [英] How to remove the decorate colors characters in bash output?

查看:21
本文介绍了如何删除bash输出中的装饰颜色字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

控制台程序 (translate-shell) 有一个带有颜色的输出,并为此使用特殊的装饰字符:^[[22m, ^[[24m, ^[[1m... 等等.

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.

我尝试使用 tr -d "^[[22m" 和 sed 's/[^[[22m]//g',但只删除了数字,而不是特殊字符 ^[

I tried with tr -d "^[[22m" and with sed 's/[^[[22m]//g', but only is removed the number, not the special character ^[

谢谢.

推荐答案

您有多种选择:

编辑

来自commandlinefu的解决方案 做得很好:

sed -r "s/x1B[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"

来自 unix.stackexchange 的解决方案 可能更好,但要长得多,因此您需要创建一个单独的脚本文件,因为它太长了,而不仅仅是做一个 shell 单行.

The solution from unix.stackexchange might be better but is much longer and so you would want to create a separate script file because it is so long instead of just doing a shell one-liner.

这篇关于如何删除bash输出中的装饰颜色字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆