I have two files. File1 with bunch of email address. File2 with list of domains.
I want to find all the email address matching the domains (also the non-matching ones)
If some one please let me know how can we do this using 'grep' from terminal.
File1.csv
abc@gmail.com
abc@fmail.com
abc@fb.com
abc@hotmail.com
abc@outlook.com
abc@live.com
File2
hotmail.com
live.com
fb.com
The output should be (and non-matching as well)
abc@fb.com
abc@hotmail.com
abc@live.com
Please consider the email file is too big and contains 2M emails to compare against 6k domains.
您可以使用 -f 从文件中读取模式:
grep -f File2 File1.csv
In your comment, you are trying to match a fixed pattern of: @[anydomainNameInFile2.txt]
in this case, you might need to add @
at the beginning of each line in File2
so you can use it as a fixed pattern.
you can do it by the following:
add @
at the beginning of each line in file2.txt using sed
command.
$ sed 's/^/@/' file2.txt > new-file.txt
don't worry that won't miss with your main file, you are saying it's about 2M field, we are saving the output to another file named new-file.txt
run the -f option grep command using the new-file.txt
file as the following:
$ grep -f newfile.txt File1.csv
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.