Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
"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
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 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .