See the -F
(fixed string, as opposed to regular expression) and -x
(exact: match the whole line) options.
grep -Fx user1@example.com text_file
would be the equivalent of:
grep '^user1@example\.com$' text_file
(remember that .
is a regular expression operator that matches any character).
-q (Quiet; do not write anything to standard output. Exit immediately with zero status if any match is found, even if an error was detected).
Use the -q
option if you only want to check if there's such a line:
grep -Fxq user1@example.com text_file &&
echo yes, that address is in that file.
If the line to search and the file name are variable:
grep -Fxqe "$email" < "$file"
Or
grep -Fxq -- "$email" < "$file"