Match all lines that end with all

Posted on

Problem :

I have a file called ithaka.txt and when I put the command:

grep “all$” ithaka.txt

It doesn’t show where the word “all” at the end of the line.

But don’t hurry the journey at all.

wealthy with all you’ve gained on the way,

I want to show the all in the first line because the word “all” is the last word of that line. I don’t want to show the all in the second line because it is not the last word of the line

Solution :

Try grep 'all$' ithaka.txt. Be sure that there are no blank spaces at the end of the lines you want to match. If such blank spaces are acceptable, try grep -P ‘alls*$’.