I want to find words contain keyword from text files. Example text file(test.txt) contains below strings.
Here is unmatched part.
" Happynimall happy-monkey:2 happy-cat:5 "
Here is unmatched part too. Here is unmatched part too.
So I tried powershell commands as follow.
$(gc test.txt).replace(' ',"`n")|select-string 'monkey','cat'
But the result failed to extract only matching word line like this.
"
Happynimall
happy-monkey:2
happy-cat:5
"
By the way, cmd "findstr" works well in extracting matching word line generated in the pipe stream.
powershell -command "$(gc test.txt).replace(' ',"""`n""")"|findstr "monkey cat"
happy-monkey:2
happy-cat:5
Why cannot "select-string" extract matching word lines only? Why can "findstr" do that? How can I make select-string give same result with findstr? Is there anyone to help me understand about it and make select-string do that? Thanks in advance:-)