[Solved by Murphy78] How to substitute findstr with find in searching string?

Discussion in 'Scripting' started by xinso, Oct 3, 2014.

  1. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,701
    14,428
    340
    #1 xinso, Oct 3, 2014
    Last edited by a moderator: Apr 20, 2017
    There is no findstr.exe in WinPE. So I wish to use find.exe to do the things:

    Code:
    findstr /i Index
    Code:
    findstr /i /C:"Index : %INDEX%"
    Thanks.
     
  2. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,419
    11,688
    240
    #2 murphy78, Oct 3, 2014
    Last edited by a moderator: Apr 20, 2017
    pretty similar, except you just use:
    Code:
    find /i "blahblah"
    if %ERRORLEVEL% neq 0 do (some error stuff here)
    The quotes are required.
    /i just ignores case, but I've had trouble using the command correctly when it's not used.
     
  3. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,701
    14,428
    340
    #3 xinso, Oct 3, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Thank you.

    And how about
    Code:
    findstr /i /C:"Index : %INDEX%"
    It needs to be exact string, like "Index : 1".

    Otherwise the output shall go wrong for there may have other numbers in WIM info.

    (I am using findstr.exe to detect images in a wim with help of Slave77. so much obliged.)
     
  4. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,419
    11,688
    240
    #4 murphy78, Oct 3, 2014
    Last edited by a moderator: Apr 20, 2017
    should be able to just use:
    Code:
    find /i "Index : %INDEX%"
     
  5. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,701
    14,428
    340
    #5 xinso, Oct 3, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    No. It won't.

    Code:
    @ECHO OFF
    :menuLOOP
    echo.
    echo.= Menu =================================================
    echo.
    for /f "tokens=2 delims=: " %%a in ('dism /English /Get-WimInfo /WimFile:d:\install.esd ^| findstr /i Index') do (
         for /f "tokens=2 delims=:" %%g in ('dism /English /Get-WimInfo /WimFile:d:\install.esd /Index:%%a ^| findstr /i Name') do (
              echo %%a : %%g
         )
    )
    set INDEX=
    echo.&set /p INDEX=Input an Index number and hit ENTER to install: ||goto:menuLOOP
    
    dism /Get-WimInfo /WimFile:d:\install.esd | findstr /i /C:"Index : %INDEX%" >nul 2>&1
    if %errorlevel% NEQ 0 (echo.&echo   Wrong number!&echo.&pause&goto:menuLOOP)
    pause
    findstr.exe

    Murphy78's Win81AIO-S14-20in1-x86-en-US-Mar2014.iso
    Code:
    = Menu =================================================
    
    1 :  Windows 8.1 (Core) S2014
    2 :  Windows 8.1 (Core) S2014 KMS-Activated
    3 :  Windows 8.1 (Core) N S2014
    4 :  Windows 8.1 (Core) N S2014 KMS-Activated
    5 :  Windows 8.1 (Core) SL S2014
    6 :  Windows 8.1 (Core) Single Language S2014 KMS-Activated
    7 :  Windows 8.1 Pro S2014
    8 :  Windows 8.1 Pro S2014 KMS-Activated
    9 :  Windows 8.1 Pro N S2014
    10 :  Windows 8.1 Pro N S2014 KMS-Activated
    11 :  Windows 8.1 Pro VL S2014
    12 :  Windows 8.1 Pro VL S2014 KMS-Activated
    13 :  Windows 8.1 Pro N VL S2014
    14 :  Windows 8.1 Pro N VL S2014 KMS-Activated
    15 :  Windows 8.1 Pro WMC S2014
    16 :  Windows 8.1 ProWMC S2014 KMS-Activated
    17 :  Windows 8.1 Enterprise S2014
    18 :  Windows 8.1 Enterprise S2014 KMS-Activated
    19 :  Windows 8.1 Enterprise N S2014
    20 :  Windows 8.1 Enterprise N S2014 KMS-Activated
    
    Input an Index number and hit ENTER to install:
    find.exe
    Code:
    = Menu =================================================
    
    FIND: Parameter format not correct
    
    Input an Index number and hit ENTER to install:
     
  6. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,419
    11,688
    240
    #6 murphy78, Oct 3, 2014
    Last edited by a moderator: Apr 20, 2017
    You maybe did it wrong... try this:
    Code:
    @ECHO OFF
    :menuLOOP
    echo.
    echo.= Menu =================================================
    echo.
    for /f "tokens=2 delims=: " %%a in ('dism /English /Get-WimInfo /WimFile:d:\install.esd ^| find /i "Index"') do (
         for /f "tokens=2 delims=:" %%g in ('dism /English /Get-WimInfo /WimFile:d:\install.esd /Index:%%a ^| find /i "Name"') do (
              echo %%a : %%g
         )
    )
    set INDEX=
    echo.&set /p INDEX=Input an Index number and hit ENTER to install: ||goto:menuLOOP
    
    
    dism /Get-WimInfo /WimFile:d:\install.esd | find /i "Index : %INDEX%" >nul 2>&1
    if %errorlevel% NEQ 0 (echo.&echo   Wrong number!&echo.&pause&goto:menuLOOP)
    pause
     
  7. xinso

    xinso MDL Guru

    Mar 5, 2009
    13,701
    14,428
    340
    #7 xinso, Oct 3, 2014
    Last edited by a moderator: Apr 20, 2017
    (OP)
    You are so great! It worked with quotes only.
    Code:
    = Menu =================================================
    
    1 :  Windows 8.1 (Core) S2014
    2 :  Windows 8.1 (Core) S2014 KMS-Activated
    3 :  Windows 8.1 (Core) N S2014
    4 :  Windows 8.1 (Core) N S2014 KMS-Activated
    5 :  Windows 8.1 (Core) SL S2014
    6 :  Windows 8.1 (Core) Single Language S2014 KMS-Activated
    7 :  Windows 8.1 Pro S2014
    8 :  Windows 8.1 Pro S2014 KMS-Activated
    9 :  Windows 8.1 Pro N S2014
    10 :  Windows 8.1 Pro N S2014 KMS-Activated
    11 :  Windows 8.1 Pro VL S2014
    12 :  Windows 8.1 Pro VL S2014 KMS-Activated
    13 :  Windows 8.1 Pro N VL S2014
    14 :  Windows 8.1 Pro N VL S2014 KMS-Activated
    15 :  Windows 8.1 Pro WMC S2014
    16 :  Windows 8.1 ProWMC S2014 KMS-Activated
    17 :  Windows 8.1 Enterprise S2014
    18 :  Windows 8.1 Enterprise S2014 KMS-Activated
    19 :  Windows 8.1 Enterprise N S2014
    20 :  Windows 8.1 Enterprise N S2014 KMS-Activated
    
    Input an Index number and hit ENTER to install: 30
    
      Wrong number!
    
    Press any key to continue . . .
    Thank you. With this, there's no need to have 20 boot.wim for WIMBoot AIO. Thanks a lot.