Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .