I have a text file with lines like this (only the last two strings matter):
1 sometext Pattern
2 sometext Pattern 5Asda5}
3 sometext Pattern asd2-asd
4 sometext Pattern a-d
5 sometext Pattern foobar
6 sometext Pattern {asd
7 Pattern Pattern something 123asd
8 Pattern sometext asd
9 Pattern 5h{1,2}b
I need to find each line with "Pattern" as last word. A word is defined in this case as string with letters and hyphens. There can be leading spaces or spaces following a string (like this: Pattern\t\t\t\t\t$)
My take at this is
egrep '(\bPattern\b +[^a-zA-Z\-]{2,} *$)|(\bPattern\b *$)' file.txt
to find all lines with Pattern followed by space(s) and a non-"word" at the end or with Pattern at the end. But the first part does not work as intended. I need another way to find the non-words.
Could you show me a way to grep line 1,2,3,6,9 but not the rest? I like to stay away from awk as we did not cover it in class.