?
Solved

how can i capture value from FINDSTR

Posted on 2008-06-13
6
Medium Priority
?
4,399 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 
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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

765 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