Windows 7 FINDSTR batch question


  1. Posts : 5
    Windows 10 Home 32 bit
       #1

    Windows 7 FINDSTR batch question


    I am programming a search using some batch files and the following works correctly.

    findstr /b /l "Pilot Name=" e:\dvd\test\ITrac.ini >out

    It creates a file OUT that has the correct information in it, so I know the FINDSTR is working. I don't need a file, I need the output in a variable so I can strip the first 11 characters off the output and continue on. I can't seem to get that right. Anyone have suggestions?
      My Computer


  2. Posts : 3,487
    Win 7 Pro x64/Win 10 Pro x64 dual boot
       #2

    This might work to set the output to a variable:

    Code:
    cmd > tmpFile  
    set /p myvar= < tmpFile  
    del tmpFile
    I'm no big genius when it comes to batch files, but it might work. Personally, if it were me, I would do it in C#. Much finer granularity and control over the processed string.

    But that's just me. :)
      My Computer


  3. Posts : 5
    Windows 10 Home 32 bit
    Thread Starter
       #3

    I was finally able to get this working using a FOR command and a FindStr together in one line of code.
    Following is the working line, FYI
    FOR /f "delims=;" %%A in ('findstr /b /c:"Pilot Name=" e:\G4_Mods\test\ITrac.ini') Do SET $B=%%A
    Thanks
      My Computer


  4. Posts : 3,487
    Win 7 Pro x64/Win 10 Pro x64 dual boot
       #4

    Glad you got it working. Thanks for posting your results to help the next person with this question. :)
      My Computer


 

  Related Discussions
Our Sites
Site Links
About 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 16:28.
Find Us