Reputation: 7038
I want to print words with matching pattern using grep/sed/awk/etc from file in Linux. I checked grep/sed/awk all prints line, I want only words from file.
Example:
I have file test.txt with following contents:
root@root:~]#cat test.txt
Notification are enabled Notification:445 Mode: valid Bookmark are enabled Bookmarks:556 Mode: Invalid Question are enabled Question:667 Mode: Unknown
Then I want to print only words with matching pattern *tion
Notification
Notification
Question
Question
Is there a way to do this in command line?
Upvotes: 1
Views: 1444
Reputation: 785246
You can use this awk command:
awk -F '[: ]' 'index($1, "tion") {print $1}' test.txt
Notification
Notification
Question
Question
Upvotes: 1
Reputation: 88644
You can try with GNU grep:
grep -oE "\w*tion" test.txt
Output:
Notification
Notification
Question
Question
Upvotes: 4