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

How to make a strict match with awk

I am querying one file with the other file and have them as following:

File1:

Angela S Darvill| text text text text   
Helen Stanley| text text text text   
Carol Haigh S|text text text text .....

File2:

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

Carol Haigh  
Helen Stanley  
Angela Darvill

This command:

awk 'NR==FNR{_[$1];next} ($1 in _)' File2.txt File1.txt

returns lines that overlap, BUT doesn’t have a strict match. Having a strict match, only Helen Stanley should have been returned.

How do you restrict awk on a strict overlap?

>Solution :

With your shown samples please try following. You were on right track, you need to do 2 things, 1st: take whole line as an index in array _ while reading file2.txt and set field seapeator to | before awk starts reading file1

awk 'NR==FNR{_[$0];next} ($1 in _)' File2.txt FS="|" File1.txt
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