strangely nothing seems to work in my script?! I'm not sure what the problem is, I'm calling this command in a while loop
while read string
do
<above commands>
done < file
and the $string is not getting expanded in some cases while in some cases it attaches ^$ to the string and nothing "grep". Please tell me what I'm doing wrong.
Your awk won't work as a) the variable is not expanded within single quotes b) the /.../ needs a string constant not a variable (while when expanded between double quotes there's a chance to work).
grep -F $string file # The variable needs to be put in double quotes
grep -x $string file # This is a whole line match, but $string is interpreted as a regex
# and the variable needs to be put in double quotes
grep "^${string}$" file # This is a whole line match, but $string is interpreted as a regex
awk '/"${string}"/ {print $0}' file # This will not work, see RudiC's comments
Also make sure there are no CR characters in your file (dos format) or none of the exact line matching will work...