如何比较两个文本文件,使用BASH完全相同的文字? [英] How to compare two text files for the same exact text using BASH?
问题描述
比方说,我有我需要提取数据出来的两个文本文件。这两个文件的内容如下:
Let's say I have two text files that I need to extract data out of. The text of the two files is as follows:
文件1:
1name - randomemail@email.com
2Name - superrandomemail@email.com
3Name - 123random@email.com
4Name - random123@email.com
文件2:
email.com
email.com
email.com
anotherwebsite.com
文件2文件1的域名列表,从电子邮件地址提取。
这些是不以任何方式相同的域名,并且是相当随机的。
File 2 is File 1's list of domain names, extracted from the email addresses. These are not the same domain names by any means, and are quite random.
我怎样才能从文件1相匹配的文件2,该域名的结果?
How can I get the results of the domain names that match File 2 from File 1?
感谢你在前进!
推荐答案
假设顺序并不重要,
grep -F -f FILE2 FILE1
应该做的伎俩。 (这工作,因为一个鲜为人知的事实:在 -F
选项的grep
并不仅仅意味着比赛这种固定字符串,它意味着匹配任何这些换行符分隔固定字符串。)
should do the trick. (This works because of a little-known fact: the -F
option to grep
doesn't just mean "match this fixed string," it means "match any of these newline-separated fixed strings.")
这篇关于如何比较两个文本文件,使用BASH完全相同的文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!