-F (fixed string, as opposed to regular expression) and
-x (exact: match the whole line) options.
grep -Fx email@example.com text_file
would be the equivalent of:
grep '^user1@example\.com$' text_file
. is a regular expression operator that matches any character).
-q option if you only want to check if there's such a line:
grep -Fxq firstname.lastname@example.org 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"
grep -Fxq -- "$email" < "$file"
You don't want:
grep -Fxq "$email" "$file"
as that would cause problems if
$file started with
If the file is sorted (in your current locale, preferably
C), you can possibly speed things up by using
comm instead of
printf '%s\n' email@example.com | comm -12 - text_file
The advantage will become more obvious when you have several email addresses to check (for instance in another sorted file):
comm -12 text_file emails_to_check
would be faster than:
grep -Fxf emails_to_check text_file