Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

up vote 0 down vote accepted
ECHO %STRING% | FIND "%FIND%"
IF ERRORLEVEL 0 ECHO %FIND%
share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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