I'm noob it's my first question, but after searching tons of answers here I still can't quite get what I want. So the problem: need to get windows version ,and edition and pass it to variable to run findstr
on it afterwards I get the variable with the edition however findstr
can't use it to find string in txt file.
what I have done: I'm using this code to get the ver and save it as var
@echo off
setlocal EnableDelayedExpansion
for /f "tokens=2 delims==" %%G in ('wmic os get Caption /value') do (
set winEdition=%%G
)
echo !winEdition!
endlocal
goto :eof
Output: Microsoft Windows 7 Enterprise
however if I run IF
statement or findstr
with !winEdition!
var I get no result with IF
and "string not found" with findstr
also if I echo
the var to a txt file I get "牣獯景⁴楗摮睯‷湅整灲楲敳†" in the txt file so I think it's encoding problem, but I can't find a way to fix it.
More details: the full code suppose to take the var from the code above, search for the string in txt file and return the next line full code:
@echo OFF
setlocal EnableDelayedExpansion
set "winEdition="
for /f "tokens=2 delims==" %%G in ('wmic os get Caption /value') do (
set winEdition=%%G
)
set numbers=
for /F "delims=:" %%a in ('findstr /I /N /C:"!winEdition!" serials.txt') do (
set /A after=%%a+1
set "numbers=!numbers!!after!: "
)
rem Search for the lines
for /F "tokens=1* delims=:" %%a in ('findstr /N "^" serials.txt ^| findstr /B "%numbers%"') do (
echo %%b
)
endlocal
goto :eof
The second part of the code works and tested with string and with var I want to automate it further. Thank you for help I am also open to alternative ways to get the result!