Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Search files with a special word

23 Feb 2012   #1
speigel205

Windows 7 32 bit
 
 
Search files with a special word

Hi, With command line, I want to search all the files *.txt in the directory C:\MyDirectory to find files that contains the word "tag" like xytag or Tag123 or /tAg. Regards


My System SpecsSystem Spec
.
23 Feb 2012   #2
Ztruker

Windows 10 Pro X64
 
 

Install Grep for Windows - a port from Linux. I use it all the time.

For example, for me to search all my html files in my web server root directory, for the word message:

grep -i "message" *.html (-i means case insensitive search)

For your case. it would be:

grep -i "tag" *.txt

You can even direct the output to a file if you want:

grep -i "tag" *.txt > results.txt

Great little program from SourceForge.

If you want to see the output and save in a file, use another little Linux port of a program called tee which the author calls wtee.

The you would do this:

grep -i "tag" *.txt | wtee results.txt

(wtee.exe has to be in a directory in your path environment variable)
My System SpecsSystem Spec
23 Feb 2012   #3
speigel205

Windows 7 32 bit
 
 

Thank you very mush for your help, it seem windows is not capable for doing this task by itself from command line not like linux did. Okay, so can you just tell me how to search for files with the extension *.txt in C:\MyDirectory if that is possible of course.
My System SpecsSystem Spec
.

24 Feb 2012   #4
Duzzy

Windows 7 Ultimate x64
 
 

EDIT: This and my next post will help with your post above.
I originally wrote this in response to your first post untill I read it again and realised it's not what you asked. I'll look into your first post tomorrow.

If you only want to output a list of these files then try this in cmd, but it will give you the full path to the file not just the filename.

dir /b /s /a:-d "C:\MyDirectory\*tag*" (output to screen)
or
dir /b /s /a:-d "C:\MyDirectory\*tag*" > results.txt (output to text file)

use dir /? for a explanation of the switches

results.txt will be in which ever folder your cmd prompt is in, eg your cmd prompt is C:\Windows\System32> then it will be found at C:\Windows\System32\results.txt. You can also specify a full path for the results.txt file.

If your only searching a single directory, not sub directories then drop the /s and you don't get the full path.

If this looks like it might work then have a play with the switches, although you might not be able to get exactly what you want.

Please let us know exactly what format you want the results returned.

? = Any char, eg. \tag?? will find tag12, tagak, tagml etc... But won't find atag12, MyTag, ThisTag123 etc...

* = Any number of any char, eg. \*tag* will find atag12, MyTag, ThisTag123, tag_me etc... \*.txt will find all text files, *.bmp will find all bitmap files, *tag*.txt will find all text files with the word tag in the filename etc...
My System SpecsSystem Spec
24 Feb 2012   #5
Duzzy

Windows 7 Ultimate x64
 
 

You might prefer this to output filename and extension only.

for /r "C:\MyDirectory\" %i in (*tag*.txt) do @echo %~nxi

It can be modified to output the fullpath, you can find the modifiers here Microsoft Corporation, about half way down the page look for Variable with modifier and Variable with combined modifiers in the first column in a blue box.

This command will output a space at the end of each line though.

To output this to a text file you need to use >> results.txt.
> creates or overwrites, >> creates or appends.

And if you plan to use this in a cmd or bat file the %i and %~nxi needs to be %%i and %%~nxi.

Sorry if I explained stuff you already know but I don't know your level of experience with cmd.
My System SpecsSystem Spec
24 Feb 2012   #6
Duzzy

Windows 7 Ultimate x64
 
 

Thought I'd have a look quick look tonight. Give this a test and see if it works.

findstr /i /s /m .*tag.* "C:\MyDirectory\*.txt" -- Outputs full path

Check it out using findstr /? or here Microsoft Corporation.

Grep could be better, I don't know, but if this works and you prefer this but you only want the filename let me know and I'll see if I can find a way.
My System SpecsSystem Spec
24 Feb 2012   #7
Ztruker

Windows 10 Pro X64
 
 

I just tried findstr and grep.

findstr found two files then throws a "Out of memory" error processing the 3rd which has 450+ hits of the search target.
grep found and reported all with no problems.
My System SpecsSystem Spec
25 Feb 2012   #8
Duzzy

Windows 7 Ultimate x64
 
 

@Ztrucker
Don't know about the "Out of memory" message, it worked for me with a file 30.9mb in size that had 74993 hits. To count the hits I used - find /i /c "com" "E:\MyDirectory\*.txt"

I would still consider using Grep because findstr would not work with 1 of my files I was using, although I don't know if Grep would do any better because something fishy was going on with that file.
It was 61.8mb in size but when I copied the text into a new file the new file was 30.9mb and when I just deleted the text from the original file it was still 2 bytes in size when it should have been 0 bytes.

I've attached the file with just a few words I put in if you would like to test Grep with it. I would also be intrested in knowing if findstr works with it on your computer. The OP would also probably like to know.

EDIT: In the screen shot Fishy File was originally "Office XP Media....". I had already copied and changed the contents before posting the screen shot. New text document is the copy of the text from "Office XP Media...." pasted into the New text document.


Attached Thumbnails
Search files with a special word-findstr.jpg  
Attached Files
File Type: txt Fishy File.txt (194 Bytes, 5 views)
My System SpecsSystem Spec
25 Feb 2012   #9
Kari

Microsoft Community Contributor Award Recipient

 

Absolutely no need to install third party tools. The Windows Search syntax for your search would be:
Code:
ext:txt content:tag
(Search all files with extension txt for the string tag.)

Here's an example. I created three txt files, Testfile 1 and Testfile 2 include string tag whereas Testfile 3 does not contain that string. First searching for all files with extension txt, syntax ext:tag:

Search files with a special word-search_1.png

As should be, Windows Search finds all three files. Now I narrow the search, searching files with extension txt containing string tag, syntax ext:txt content:tag:

Search files with a special word-search_2.png

Testfile 1 and Testfile 2 contain string tag, therefore they are found.

Easy and fast.

Kari


My System SpecsSystem Spec
25 Feb 2012   #10
Duzzy

Windows 7 Ultimate x64
 
 

@Kari
1st - The OP want's to do it from the command line
2nd - It doesn't work with wildcard char to find, and I quote, like xytag or Tag123 or /tAg
3rd - it's much slower than the command line if working with large files, eg. 30.9mb without the folder being indexed.
4th - Forced to search subfolders if normally searched

Actually number 2 is true and false for me, changing it to - ext:txt content:*tag*, and adding Tag123 or /tAg to one file it works but adding xytag it does not. File also contains avtag and copytagall in all test.
My System SpecsSystem Spec
Reply

 Search files with a special word




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Search text file contents for special character
Hey, I'm trying to search the contents of some text files. The string I am searching for is SAP*. As you can probably guess when I type * I get everything that starts with the word SAP. I tried using ~"SAP*", ~SAP"(*)" etc. but it continues to show me everything that starts with SAP. I can't...
General Discussion
im in search for a special apdater
ok heres the deal i have a car pc a car HU and a flip down i want to purchase soon. im trying to avoid purchasing a vga/rca input flip down because they are pricey. so i need a adapter that does the following input : rca vga output rca
Hardware & Devices
Windows 7 search files and folders vs Outlook 2007 search
Hello, Can someone tell me some specifics and pinpoint the differences (or maybe a good website) that would pinpoint the differences between the Windows 7 search and the outlook 2007 search? I know the outlook search searches through email but are there other difference I am overlooking between...
General Discussion
Windows Search and Special Characters
Hi. I am trying to use windows desktop search to find all files that have a filename stucture of filename1_(2).jpg, filename2_(2).jpg so that I can mass delete them. I can not seem to find a way to search for this a windows search seems to want to include everything between the ( and ) and...
General Discussion
Word Search
I have about a hundred files in 10 folders and they are in one folder so how can I do a word search though all hundred files? They are Word Documents.
General Discussion
In search for a special theme...
Hi guys. I'm trying my luck here. Hum, I need a good looking dark theme that both skin the Aro Glass and Aero Basic. See, I use Audition 1.5 and it desactivate Aero, and, at the same, I lose my skin. :\ Is there a theme like Sergio's "Red Fusion" for x86 that skins Aero and Aero Basic? ...
Themes and Styles


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 17:19.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App