Quote:
Originally Posted by udiubu
double quote and curly brackets removal do the job
do
grep "^$word$" infile
done
|
That works in situations where the word you are searching for takes up the whole line and there are not even any leading or trailing spaces.
If by 'exact match' you mean the string is not a substring but is a standalone word, then you need a more general approach for finding the whole word then you can also search for the null-string word boundaries. Most systems will refer to those as \< and \> for the start of a word boundary and the end of a word boundary respectively. So the following would find the word if it is whole, regardless of where on the line it is or how much of the line it takes up:
Code:
grep "\<${word}\>" infile;
Some systems might require it to be written a little differently,
Code:
grep "[[:<:]]${word}[[:>:]]" infile;
but that won't work with GNU
grep