How can I display all the lines that end with a certain character using grep?

1

0

I want to write a command to display all the lines in a given file that end with a ";" or a "." character.

Why does this not work?

grep ".';' | .'\.'" filename

ricedragon

Posted 2011-10-04T01:02:36.703

Reputation: 57

I fixed your titles so they were actually meaning something. It would be great – if you post a question – to make your title really specific about what you want to do, not "Unix grep". – slhck – 2011-10-04T07:52:38.513

Answers

4

grep "[;.]$" list-of-files

This matches any line which contains either ; or . followed by the end of the line.

JRobert

Posted 2011-10-04T01:02:36.703

Reputation: 6 128

.. how does this work ? – ricedragon – 2011-10-04T03:08:55.540

@ricedragon it's regex notation. [abc] means a or b or c. $ means match end of line. play with regex coach and see http://www.regular-expressions.info/ and grep -P is a bit more flexible.

– barlop – 2011-10-04T04:04:25.860