list lines ending with a period or semicolon list lines ending with a period or semicolon linux linux

list lines ending with a period or semicolon


With grep (and egrep) a dollar sign ($) matches the end of a line, and a carret (^) matches the beginning of a line. So, for example, if you wanted to match lines containing exactly the word "fish" and no other characters you could use this:

grep '^fish$'

It's important to use single quotes to wrap the search expression so that bash doesn't do anything funny to it.

So, to answer your question, you will need to use the search pattern '[.;]$' to match either a . or ; character followed by an end of line character. I am using this as an example test file:

$ cat testfile onetwo;three.four:

And here is the result:

$ grep '[.;]$' testfile two;three.

If you also want to allow whitespace at the end of the line, then use this pattern: '[.;][ \t]*$' which will match with any number of spaces or tab characters after the . or ;.


This should do it:

$ grep -E '(;|\.)$'

The -E switch enables regular expression mode. The expression simply matches a line ending in either a semicolon or a period.

Note: I haven't tested this.


Without -E:

grep '\.\|;$' filename