使用 grep 查找所有电子邮件 [英] Using grep to find all emails
本文介绍了使用 grep 查找所有电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何正确构造grep"linux 程序的正则表达式,以在/etc 目录中查找所有电子邮件?目前,我的脚本如下:
How to properly construct regular expression for "grep" linux program, to find all email in, say /etc directory ? Currently, my script is following:
grep -srhw "[[:alnum:]]*@[[:alnum:]]*" /etc
它工作正常 - 看到一些电子邮件,但是当我修改它时,在@"符号之前和之后捕捉一个或多个字符......
It working OK - a see some of the emails, but when i modify it, to catch the one-or-more charactes before- and after the "@" sign ...
grep -srhw "[[:alnum:]]+@[[:alnum:]]+" /etc
...它完全停止工作
此外,它不会捕获Name.LastName@site.com"形式的电子邮件
Also, it does't catches emails of form "Name.LastName@site.com"
帮助!
推荐答案
这是另一个例子
grep -Eiorh '([[:alnum:]_.-]+@[[:alnum:]_.-]+?.[[:alpha:].]{2,6})' "$@" * | sort | uniq > emails.txt
此变体适用于 3 级域.
This variant works with 3 level domains.
这篇关于使用 grep 查找所有电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文