grep在彩色线条上 [英] grep on colored lines

查看:98
本文介绍了grep在彩色线条上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个简单的PHP shell脚本,用于解析文件并输出某些元素。

它生成大量输出。在不同的(bash)颜色中,绿色表示确定,黄色表示警告,红色表示错误等。

在开发过程中,我想过滤一些行。例如所有包含红色文本的行。



我可以使用 grep (或其他)命令吗?

解决方案

我不知道你的输入是什么样的,但作为概念证明,你可以过滤 ls 使用绿色的输出:

  ls --color = always | grep'^ [\ [01; 32m'

其他颜色的查找表可以在这里找到: http://en.wikipedia.org/wiki/ANSI_escape_code#Colors



提示:如果您不知道,请输入上面的 ^ [部分如大多数终端上的 Ctrl-V Esc (或实际上 Ctrl-V Ctrl - [))。
我相信会有一些选项让grep理解 \x1B ,但我没有找到它


I wrote a simple PHP shell script which parses files and outputs certain element.
It generates lots of output. In different (bash) colors, green for OK, yellow for warnings, red for errors, etc.

During development I want to filter some lines out. For example all lines that contains red text.

Can I use a grep (or other) command for this?

解决方案

I have no idea what your input looks like, but as a proof of concept you can filter any lines in ls output that use green colour:

ls --color=always | grep '^[\[01;32m'

The lookup table for other colours can be found here: http://en.wikipedia.org/wiki/ANSI_escape_code#Colors

Hint: In case you didn't know, the ^[ part above should be entered like Ctrl-VEsc (or indeed Ctrl-VCtrl-[ on most terminals). I'm sure there will be some option to grep to make it understand \x1B instead, but I haven't found it

这篇关于grep在彩色线条上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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