You may need to use -w
in your grep
. This way it will just match whole words:
$ grep -w 1989 file
719048, 1989, Salt Lake
260368, 1989, Utah
185236, 1989, Davis
157847, 1989, Weber
Notice the difference:
$ grep 1989 file
719048, 1989, Salt Lake
260368, 1989, Utah
219893, 1980, Utah <---- without -w, this matches
185236, 1989, Davis
157847, 1989, Weber
If you want, awk
can also do the job by indicating the field you are checking:
$ awk '$2~1989' file
719048, 1989, Salt Lake
260368, 1989, Utah
185236, 1989, Davis
157847, 1989, Weber