Using sed how can I print all lines in a file that has the letter a in the last word?
I tried something like this sed -n -E '/[ e]./w\./p' < 'textfile'
But Im very new to sed so not really understanding it.
CodePudding user response:
You might use
sed -nE '/[^a[:space:]]*a[^[:space:]]*[[:space:]]*$/p' textfile
Here:
-ndisable the default printing of the line-Eextended regular expressions/pprint the addressed line
The pattern matches:
[^a[:space:]]*Optionally match non whitespace characters except for theacharaMatch theachar[^[:space:]]*Match optional non whitespace chars[[:space:]]*Match optional spaces$End of string
Example input
this is a test
a
atest
testa
testatest
atest this is
testa this is
testatest this is
this is a test$%a
a word with special chars !@#$%a!@#$%
a word with special chars !@#$%a!@#$% bcd
Output
a
atest
testa
testatest
this is a test$%a
a word with special chars !@#$%a!@#$%
