Getting the last match in a file using grep

You could try

grep pattern file | tail -1

or

tac file | grep pattern | head -1

or

tac file | grep -m1 pattern

Leave a Comment