[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Batch file for findstr

Posted on 2005-05-10
10
Medium Priority
?
2,908 Views
Last Modified: 2010-08-05
Hello,

I am no amateur in batch scripting...With help about findstr from the command line, i was able to make the findstr work for me in the commandline.

My command is: findstr /r /i /m "AddImgIfNextIsSame" e:\dap\dapcore\ho\v97\mstrres\ddtlib\*.* >> H:\dap\kk2.txt
and it works fine.

Two things I am struggling with are:

1) How to add another directory to this findstr command and make it work. I tried:
findstr /r /i /m "AddImgIfNextIsSame" /d:e:\dap\dapcore\ho\v97\mstrres\ddtlib\*.*;e:\dap\dapcore\ho\v10\mstrres\ddtlib\*.* >> H:\dap\kk2.txt
but it gives cannot open the directory error.

2) How to make this work from batch file. I put the exact same command in a notepad and renamed it as .bat file, but is not working.

Pls suggest.

Thanks


0
Comment
Question by:kamur
  • 4
  • 2
7 Comments
 
LVL 30

Expert Comment

by:SteveGTR
ID: 13968965
I don't believe that you can specify multiple files. You can include wildcards in the one file specification to process more than one files, but that doesn't help you. I'd issue two findstr commands in a batch file (in any form you want).

Good Luck,
Steve
0
 

Author Comment

by:kamur
ID: 13969110
I can live with 2 findstr commands, but how do I make the simple findstr into a batch file...thankz
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 13969373
I didn't notice that D parameter so, your processing should work great with one line as follows:

findstr /r /i /m /D:e:\dap\dapcore\ho\v97\mstrres\ddtlib;e:\dap\dapcore\ho\v10\mstrres\ddtlib  "AddImgIfNextIsSame" *.* >> H:\dap\kk2.txt

You could make it into a batch file by using notepad and adding this line:

@findstr /r /i /m /D:e:\dap\dapcore\ho\v97\mstrres\ddtlib;e:\dap\dapcore\ho\v10\mstrres\ddtlib  "AddImgIfNextIsSame" *.* >> H:\dap\kk2.txt
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

Author Comment

by:kamur
ID: 13969689
Thanks Steve, it works great with one line in the commandprompt.

However, the batch file is not working..as if it is processing forever...it never ends and no output also..

Thanks
0
 
LVL 30

Accepted Solution

by:
SteveGTR earned 200 total points
ID: 13970781
You could try to remove the redirection from the batch file to see what is occuring:

@findstr /r /i /m /D:e:\dap\dapcore\ho\v97\mstrres\ddtlib;e:\dap\dapcore\ho\v10\mstrres\ddtlib  "AddImgIfNextIsSame" *.*
0
 
LVL 5

Expert Comment

by:brianadkins
ID: 13977139
I notice that you're using the '/r' option which enables the use of regular expressions in your search criteria.  In most other tools (perl, php, etc.) enabling regex matching can really slow performance as opposed to plain text matching.

In your case, you are not using a regex search string so I would omit the /r option to see if the performance improves at all.

Also, if you use findstr on each directory individually, are you still seeing the same performance problem? (when you add the two times together?)

-Brian
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 14217058
My solution worked.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question