1

Is there a way in Windows to get a matching string within a string?

echo hereisastring | find "is"  and just display is

without using grep

The following worked using FIND. credit to Hello71

C:\>echo abcd | find "bc" >nul && if errorlevel 0 echo bc
bc

C:\>
0
ECHO %STRING% | FIND "%FIND%"
IF ERRORLEVEL 0 ECHO %FIND%
  • C:\test>echo abcd | find "bc" if errorlevel 0 echo "bc" <-- doesn't seem to work. Does this have to be multiple lines? does it have to use environment variables? – barlop May 8 '11 at 20:13
  • Can you give a full working example? I don't really understand why at one point you've put an environment variable in quotations and in another point not. – barlop May 8 '11 at 20:32
  • @barlop: You need to use && to separate commands in Command Prompt. FIND requires its parameter to be in quotes. – Hello71 May 8 '11 at 21:01
  • @Hello71 I couldn't get the example with environment variables to work because set is a bit funny, putting spaces or new lines in. Have you managed to get it to work with environment variables? I did get it working without though. – barlop May 8 '11 at 21:59
  • @barlop: The environment variables were for the purpose of the example. – Hello71 May 8 '11 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.