shell - Batch Script Comparison -
i doing comparison using batch script, can search string , states if exists or not, having trouble when string has 2 sections: please see code below,
@echo off set key0="first number"="1000" set key1="first number" set key2== set key3="1000" set key4=%key1%%key2%%key3% /f "tokens=*" %%a in (file.txt) call :processline %%a findstr /x %key4% file.txt if %errorlevel%==0 ( echo key exists ) else ( echo no ) pause goto :eof
if search key0 or key4 result no. if search key1, key2 or key3 key exists....
any ideas on how search string containing 2 separate words in quotes?
a working solution is:
@echo off set key0=\"first number\"=\"1000\" set key1=\"first number\" set key2== set key3=\"1000\" set key4=%key1%%key2%%key3% findstr /x /c:"%key4%" file.txt if %errorlevel%==0 ( echo key exists ) else ( echo no ) pause
- each double quote in search string must escaped backslash.
- option
/c:
must used literal string search instead of regular expression search. - the entire search string must in double quotes because of containing space character.
i used documentation of findstr microsoft , of command output in command prompt window after entering findstr /?
Comments
Post a Comment