我如何使用xargs递归解析电子邮件地址的文本/html文件



我尝试用xargs和grep从文本/html文件目录递归地解析电子邮件地址,但这个命令一直包括路径(我只想在我的结果email .csv文件中的电子邮件地址)。

find . -type f | xargs grep -E -o "b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,6}b" >>  ~/emails.csv

你能解释一下我的grep命令有什么问题吗?我不需要它排序或唯一。我想匹配文件中所有出现的电子邮件地址。我需要使用xargs,因为我在20 GB的文本文件中解析电子邮件。

谢谢。

当您告诉grep在多个文件中搜索时,它会在搜索结果中添加相应的文件名。尝试以下操作查看效果…

首先,在单个文件中搜索:

grep local /etc/hosts
# localhost is used to configure the loopback interface
127.0.0.1   localhost

现在搜索两个文件:

grep local /etc/hosts /dev/null
/etc/hosts:# localhost is used to configure the loopback interface
/etc/hosts:127.0.0.1    localhost

要抑制找到匹配的文件名,将-h开关添加到grep,如下所示

grep -h <something> <somewhere>

最新更新