如何确定文件中的哪个模式与 grep 匹配?
我使用 procmail 对收件箱进行广泛的排序。我的倒数第二个食谱将传入的发件人:与历史上良好的电子邮件地址和电子邮件地址模式的(非常)长的白色/金色列表相匹配。秘诀是:
# Anything on the goldlist goes straight to inbox :0 * ? formail -zxFrom: -zxReply-To | fgrep -i -f $HOME/Mail/goldlist { LOG="RULE Gold: " :0: $DEFAULT }
最终的秘诀是将所有剩余的内容放入可疑文件夹中,以将其作为可能的垃圾邮件进行检查。 Goldlist 目前有 7384 行长(哎呀......)。每隔一段时间,我就会收到一封漏掉的垃圾邮件,我想修复失败的模式。我想我不久前读到了 grep 中的一个特殊标志,它有助于显示匹配模式,但我再也找不到了。有没有办法使用 grep 显示与扫描文本匹配的文件中的模式?或者另一个类似的工具可以回答除了编写脚本来逐个模式扫描的问题之外的问题?
I use procmail to do extensive sorting on my inbox. My next to last recipe matches the incoming From: to a (very) long white/gold list of historically good email addresses, and patterns of email addresses. The recipe is:
# Anything on the goldlist goes straight to inbox :0 * ? formail -zxFrom: -zxReply-To | fgrep -i -f $HOME/Mail/goldlist { LOG="RULE Gold: " :0: $DEFAULT }
The final recipe puts everything left in a suspect folder to be examined as probable spam. Goldlist is currenltty 7384 lines long (yikes...). Every once in a while, I get a piece of spam that has slipped through and I want to fix the failing pattern. I thought I read a while ago about a special flag in grep that helped show the matching patterns, but I can't find that again. Is there a way to use grep that shows the pattern from a file that matched the scanned text? Or another similar tool that would answer the question short of writing a script to scan pattern by pattern?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
grep -o 将仅输出匹配的文本(而不是整行)。这可能有帮助。否则,我认为您需要编写一个包装脚本来一次尝试一种模式。
grep -o will output only the matched text (as opposed to the whole line). That may help. Otherwise, I think you'll need to write a wrapper script to try one pattern at a time.
我不确定这是否对您有帮助。有一个“-o”参数可以只输出匹配的表达式。
从手册页:
I'm not sure if this will help you or not. There is a "-o" parameter to output only the matching expression.
From the man page: