Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to search several words at the same time in a text file.

For example think I want to search these 3 words: Majid,superuser,device

Normally I should search for them one by one, and I can not search all of them at the same time. So I want to search these words at the same time in a text file.

I want to enter those 3 words in a text file, one word per line. Let's name it SearchText. Now I have a Target Text which I want to search those words in it. Let's name it TargetText.

I want to tell an app or something similar to get words from SearchText and find them in TargetText and Highlights them or gives me the find result.

I hope I'm clear. So can anyone hep me?

share|improve this question
    
For all of the words, or for any of the words? –  JdeBP Sep 11 '11 at 8:10
    
Hi JdeBP, For all, I mean it searches for example for those 3 words (Majid,superuser,computer) and if it finds any of them, then it highlights them or give me the result. –  Stranger Sep 11 '11 at 8:14
1  
"For all, I mean any." doesn't answer my question in a way that conveys what you want. You really need to make it clear what you want to match, and what you do not, before anyone can properly construct an answer to this question that not only says "Yes." but proceeds to explain how. Edit the question to make it clear what you want. –  JdeBP Sep 11 '11 at 8:27
    
What OS do you prefer? The answer will be different if it's windows or linux –  Nifle Sep 11 '11 at 8:38
    
Hi Nifle, I'm using windows. –  Stranger Sep 11 '11 at 9:29

2 Answers 2

up vote 0 down vote accepted
grep "Majid|superuser|device" filename.txt

On Windows you'll have to install Cygwin, GnuWin32, UnxUtils or similar.

If the words must come from a file you could write a shell script to read that file and construct the argument to grep.

See also http://stackoverflow.com/questions/87350/what-are-good-grep-tool-for-windows which suggests the native

findstr /C:"Majid superuser device" filename.txt
share|improve this answer
    
Hi RedGrittyBrick, But how to save the result? Is it possible to save find words in a text file? –  Stranger Sep 11 '11 at 11:20
    
Use redirection to save the results - append "> savedresult.txt" to the command –  RedGrittyBrick Sep 11 '11 at 20:31

Keep it simple. When on a Windows platform - Use Windows commands/tools.

I'd use findstr as follows:

C:\some\directory>findstr "Majid superuser device" somefile

There is no need for SearchText to exist when searching for 3 keywords - but you could do this:

C:\some\directory>notepad SearchText.

Enter your keywords separated by CRLF. Save file and do this:

C:\some\directory>findstr /g:SearchText somefile

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.