With grep (and egrep ), the dollar sign ( $ ) matches the end of the line, and carret ( ^ ) matches the start of the line. So, for example, if you want to combine strings containing exactly the word "fish", and you cannot use any other characters:
grep '^fish$'
It's important to use single quotes to wrap the search expression so that bash doesn't do anything funny for it.
So, to answer your question, you will need to use the search pattern '[.;]$' To match the character . or ; followed by the end of line character. I use this as an example of a test file:
$ cat testfile one two; three. four:
And here is the result:
$ grep '[.;]$' testfile two; three.
If you also want to allow spaces at the end of a line, use this pattern: '[.;][ \t]*$' , which will match any number of spaces or tabs after . or ; .
source share