I have a file dict containing one integer on each row
123
456
I want to find lines in file file that contain exactly the integers in dict.
If I use
$ grep -w -f dict file
I get false matches such as
12345 foo
23456 bar
These are false because 12345 != 123 and 23456 != 456. The problem is that the -w option considers digits as word characters too. The -x option will not work either as the lines in file can have other text. What’s the best way to do this please? It will be great if the solution can offer progress monitoring and a good performance on dict and file of large sizes.
A fairly general method using
awk:Explanation:
To process multiple files using bash loop:
If you are interested in using
teeon multiple files, you may like to try something like this:This will show you the name of the file being process and the matching record found, and write a ‘log’ to file called
output.