Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Grep Match entire email multiple lines

Hello I have to files:

I have this fist file

./j/n:jwillow@gmail.com:Test1
./n/o:nanofranky@list.ru:Test2
./j/r:franky@list.ru:Test2
./j/d:jdmq77@hotmail.com:Test3
./x/s:xsebastianmenendez@hotmail.com:Test4
./r/s:rsebastianmenendez@hotmail.com:Test5
./w/i:willow@gmail.com@gmail.com:Test6

And I want it to match this second file, but the whole email, not just the appearance of the word:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

willow@gmail.com
franky@list.ru
jdmq77@hotmail.com
sebastianmenendez@hotmail.com

So I want the output to be:

./j/r:franky@list.ru:Test2
./j/d:jdmq77@hotmail.com:Test3
./w/i:willow@gmail.com@gmail.com:Test6

I try with grep -f, but, since the words appear in the email, I get all the lines of the first file, not just the ones that matches with the whole email.

Regards!

>Solution :

Use the -w argument.

grep -w 'willow@gmail.com' file.txt

Output:

./w/i:willow@gmail.com@gmail.com:Test6

Bash script example to compare two files:

#!/bin/bash

strings_file="search_for.txt"
input_file="in.txt"

grep -w -F -f "$strings_file" "$input_file"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading