Spaces in set
command is significant. set month = 10
will create a variable named "month "
(with space after) with a value " 10"
(with a space before). Just try echo %month %
and see
Because the variable %month%
is not available, if /I not %%i == %month% (
will be expanded as if /I not %%i == (
, which results in an invalid syntax. Another lesson: always surround if
parameters with ""
so if the variable expands to an empty string it'll still work
Besides, to avoid a trailing space is included on each line, you should move the redirection to before the command
The final result will be like this
set month=10
for /f "tokens=*" %%i in (input.txt) do (
if /I not "%%i" == "%month%" (
>>"output.txt" echo %%i
)
)