如何截断由grep或ack返回的长匹配行 [英] How to truncate long matching lines returned by grep or ack

查看:146
本文介绍了如何截断由grep或ack返回的长匹配行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在通常有很长行的HTML文件上运行ack或grep。我不想看到重复包裹的很长的线条。但我确实希望看到围绕与正则表达式匹配的字符串的长整行的那一部分。如何使用Unix工具的任意组合来获得这个结果?

I want to run ack or grep on HTML files that often have very long lines. I don't want to see very long lines that wrap repeatedly. But I do want to see just that portion of a long line that surrounds a string that matches the regular expression. How can I get this using any combination of Unix tools?

推荐答案

您可以使用grep选项 - o ,可能与将您的模式更改为。{0,10}<原始模式>。{0,10} in为了看到它的一些上下文:

You could use the grep option -o, possibly in combination with changing your pattern to ".{0,10}<original pattern>.{0,10}" in order to see some context around it:


       -o, --only-matching
              Show only the part of a matching line that matches PATTERN.

..或 -c

..or -c:


       -c, --count
              Suppress normal output; instead print a count of matching  lines
              for  each  input  file.  With the -v, --invert-match option (see
              below), count non-matching lines.

这篇关于如何截断由grep或ack返回的长匹配行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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