Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
DOS/Other
Tag Cloud
access acer asus bios bsod computer crash desktop dns driver drivers error ethernet excel freeze gaming graphics hard drive hardware hdmi internet laptop malware memory monitor motherboard network printer problem ram registry repair router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > DOS/Other >
Solved: findstr Across Multiple File Types

Reply  
Thread Tools
corykv's Avatar
Junior Member with 2 posts.
 
Join Date: Sep 2009
23-Sep-2009, 12:41 PM #1
Solved: findstr Across Multiple File Types
Using findstr to find strings is fairly easy. I am trying to search recursively through a path, but only want to check one of three file types: *.java, *.properties or *.xml.

I know how to do one:

findstr /pinsc:"my weird search string" *.java


But how to tell findstr to look only in *.java, *.properties and *.xml files without having to run findstr 3 times?

Thanks in advance.

corykv
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
23-Sep-2009, 04:14 PM #2
Use the DIR cmd in a for loop.

Code:
FOR /F "tokens=*" %%A IN ('dir /b /a-d /s *.java *.properties *.xml') DO findstr /pinc:"my weird search string" "%%A"
I am not sure if you could also do this. I have never tried it.
Code:
findstr /pinsc:"my weird search string" *.java *.properties *.xml
ghostdog74's Avatar
Member with 146 posts.
 
Join Date: Dec 2005
23-Sep-2009, 09:21 PM #3
here's an alternative if you can download stuff. Go to here and download grep. then on the command line

Code:
C:\test>grep "line" *txt *.java
type grep --help on the command line for more options (which are way better than what findstr has)
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
24-Sep-2009, 08:37 AM #4
Quote:
Originally Posted by ghostdog74 View Post
here's an alternative if you can download stuff. Go to here and download grep. then on the command line

Code:
C:\test>grep "line" *txt *.java
type grep --help on the command line for more options (which are way better than what findstr has)
How is that going to recurse through the sub-directories?
corykv's Avatar
Junior Member with 2 posts.
 
Join Date: Sep 2009
24-Sep-2009, 02:45 PM #5
Squashman, ghostdog,

Sometimes the simplest course of action is the easiest... Thanks for your help... this is what worked:

Code:
findstr /pinsc:"my search string" *.xml *.java *.properties
Squashman, I am a longtime user/lover of grep, unfortunately, I don't have the option on the machine I'm working on (corporate). Beautiful solution, though... none of the options I have ever seen have shown that ability --

Thanks, guys.

corykv
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
24-Sep-2009, 02:50 PM #6
You could use GREP. It is a self contained EXE. No need to install it. Nobody is going to know it is there. Grep does have options to recurse directories but wasn't shown in GhostDog's example.
ghostdog74's Avatar
Member with 146 posts.
 
Join Date: Dec 2005
25-Sep-2009, 11:34 AM #7
Quote:
Originally Posted by Squashman View Post
How is that going to recurse through the sub-directories?
i guessed you have already found out, but just for completeness, the -R option does that job.
Reply

Tags
command line, findstr, wildcard

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:49 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.