Search for a specific word and print only the word from the input file

Hi,

I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file.

Ex:

$ cat "sample.log"
I am searching for a word which is present in this file
We can do a pattern search using grep but I need to cut only the word which has the word I'm looking.
Any help would be appreciated!

I am looking for a command like below

$ magic_command wo "sample.log"
word
word word
word
would

Depending on your version of grep you can use the "-o" flag to get the exact match only. Are you bothered about retaining exact matches on the same line as one another? I am not sure looking at your example output as there are only 4 matches of "wo' not 5 as you have given.

Try this if you are not bothered about that:

tr ' ' '\n' < sample.log|grep wo