grep exact match

Is there any way to grep for an exact match?

I am looking for lines containing only “68” but grep “68” /etc/services shows a lot more.

Thanks.

Try grep -w your_string. :slight_smile:

e.g. grep -w “68” /etc/services

@heders254: The answer given above is correct, but let’s look at your phrasing. By exact match, here you meant 68 as a word, for which the -w option is the correct one to use. However in other situations, if you meant you wanted the string “68” (with the double quotes), the problem is one of getting the quotes past the shell. You can do this:

grep '"68"' filename

or perhaps

grep "\"68\"" filename

I’ll leave it to you to work out how to grep for ‘68’ (with the single quotes).