?
Solved

how can i capture value from FINDSTR

Posted on 2008-06-13
6
Medium Priority
?
4,629 Views
Last Modified: 2008-08-07
Hi all,

i my batch script i need to capture the result of FINDSTR function into a variable ,so that i can use that value for further processing in the same script
in the below given code (in code snippet) result of findstr /I /C:"folder"  %sd%\fname.log  should be captured into a variable
how can i do that,please suggest

many thanks in advance
cls
@ECHO OFF
set sd=d:
set balu1 =1
findstr /I /C:"folder"  %sd%\fname.log  > %balu1%
if not errorlevel 1  goto :ABORT
:ABORT
 
echo %balu1%

Open in new window

0
Comment
Question by:kunchesm
  • 5
6 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 21778487
in general you can do this:

for /f %%V in ('/I /C:"folder"  %sd%\fname.log') do set MYVAR=%%V

@echo %MYVAR%
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 21778510
OOPS!  I left out the findstr command.  Correcting:

   for /f %%V in ('findstr /I /C:"folder" %sd%\fname.log') do set MYVAR=%%V




...but in you case you need to also redirect the output to a file, so do both:


findstr /I /C:"folder"  %sd%\fname.log  > %balu1%
   for /f %%V in ('findstr /I /C:"folder" %sd%\fname.log') do set MYVAR=%%V
if not errorlevel 1  goto :ABORT



0
 
LVL 33

Expert Comment

by:knightEknight
ID: 21778540
hmm, I don't thing the order makes a difference here, but just in I'm swapping them:


  for /f %%V in ('findstr /I /C:"folder" %sd%\fname.log') do set MYVAR=%%V
  findstr /I /C:"folder"  %sd%\fname.log  > %balu1%
  if not errorlevel 1  goto :ABORT
0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
LVL 33

Expert Comment

by:knightEknight
ID: 21778692
also, I'm assuming from your question that the string you are trying to find only occurs once in the file.  If you need to do something with MYVAR for multiple occurrances in the file then this will changes things considerably.  Let me know.
0
 

Author Comment

by:kunchesm
ID: 21790919
hi Ralph Brown

thank you so much....it worked.....am new to batch script.....thanks for all your suggestions and time.....
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 150 total points
ID: 21793303
I'm glad it worked for you.  :)


  for /f %%V in ('findstr /I /C:"folder" %sd%\fname.log') do set MYVAR=%%V
  findstr /I /C:"folder"  %sd%\fname.log  > %balu1%
  if not errorlevel 1  goto :ABORT
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

840 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