for loop - Use of relational operators when reading a file from CMD -
i trying create command line program outputs numbers file greater (larger than) specified one. there's file output.txt lots of numbers (one per line) , need ones less 5000.
here's part of code, doesn't work expected:
choice /c 12 set /p comparative_number="input number: " if %errorlevel%==2 goto less_operation /f %%a in (%outputfile%) if %%a gtr %comparative_number% echo %%a echo. & echo end of output & exit /b :less_operation /f %%a in (%outputfile%) if %%a lss %comparative_number% echo %%a echo. & echo end of output & exit /b
what doing wrong?
the command extensions enabled default. if batch script depends on command extensions when using gtr
, lss
in if condition advisable enable them explicitly.
the integer numbers must listed in file referenced via environment variable outputfile
line line, example:
50 23 478 -3425 9071
a batch code worked:
@echo off setlocal enableextensions set "outputfile=c:\temp\file numbers listed line line.txt" echo. echo please choose comparison: echo. echo 1 ... greater echo 2 ... smaller echo. choice /c:12 /n /m "your choice: " echo. set "comparative_number=0" set /p "comparative_number=input number: " echo. if %errorlevel%==2 goto less_operation /f "usebackq" %%a in ("%outputfile%") if %%a gtr %comparative_number% echo %%a echo. echo end of output endlocal exit /b :less_operation /f "usebackq" %%a in ("%outputfile%") if %%a lss %comparative_number% echo %%a echo. echo end of output endlocal exit /b
why code not work in comparison modified code depends on name of output file, how numbers listed in output file , how have used command choice.
Comments
Post a Comment