I want to read a text file where every line has a number. Negative numbers need to be replaced by 0 and written to a new file along with the rest of the positive numbers.
The problem is that I want to save the value of a line, i.e. %%a into a new variable. Then I'll check if the first character of that variable is '-' if so, I'll set the value to 0 for that line in the final file if not, it will remain as is.
But I cannot save the line value into anything. Below is my code. 3.txt is the original file, tempfile.txt is the final file.
set filem=3.txt
set tempfile=tempfile.txt
for /f "tokens=*" %%a in (%filem%) do (
set linevalue=%%a
IF %linevalue:~0,1% EQU - (
echo 0>>%tempfile%
) ELSE (
echo %%a>>%tempfile%
)
)
pause