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:\>
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 – 2011-05-08T20:13:57.437
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 – 2011-05-08T20:32:34.863
@barlop: You need to use && to separate commands in Command Prompt.
FIND
requires its parameter to be in quotes. – Hello71 – 2011-05-08T21:01:18.927@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 – 2011-05-08T21:59:52.463
@barlop: The environment variables were for the purpose of the example. – Hello71 – 2011-05-08T22:06:57.230
@Hello71 So are you able to get it working using environment variables? – barlop – 2011-05-08T22:07:35.653
@barlop: No, the code was untested. – Hello71 – 2011-05-08T22:55:03.723
accepted since it was pretty much there. – barlop – 2011-05-08T23:08:16.567