grep with variable

Hi, I can't get this script to work (returns 0, should return 3):

$ cat A.lst | \
while read LINE
do
        echo "$LINE"
        grep -c "$LINE" B.tmp
done> > > > >
Socket
0
$

but in contrast this one works fine (returns 3 as expected):

$  LINE=Socket
$ grep -c $LINE B.tmp
3
$

Note: A.lst contains one line with a string: Socket
B.tmp contains 3 lines with strings: Socket

Thank you!

Whitespace around the "Socket" in A.lst?

No, there is not. Even if there is it should work as Socket has spaces around in B.tmp file:

$ LINE=" Socket "
$ grep -c $LINE B.tmp
$ 3

Hi.

Try od -c A.lst , I'm also of the opinion that there's something funky in it.

Also, in your last code example, you didn't replicate the quotes around the grep pattern. Those make a large difference.

Why not:

grep -c -f A.list B.tmp

Regards

Thanks for your help, it works after I did this:

$  od -c A.lst
0000000   S   o   c   k   e   t  \r  \n
0000010
$ dos2unix A.lst A.lst
$  od -c A.lst
0000000   S   o   c   k   e   t  \n
0000007

The file was created under Win OS.