To avoid matching 12345 when you're looking for 123, grep with exact word matches -Fw.

e.g.

% echo "123" | tee a.txt b.txt
% echo "1234\r\n12345" >> b.txt

% grep -f a.txt b.txt
123
1234
12345

% grep -Fwf a.txt b.txt
123