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:\>
link|improve this question

69% accept rate
feedback

1 Answer

up vote 0 down vote accepted
ECHO %STRING% | FIND "%FIND%"
IF ERRORLEVEL 0 ECHO %FIND%
link|improve this answer
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
show 3 more comments
feedback

Your Answer

 
or
required, but never shown

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