、私はそれを行う方法を見つけました:
setlocal EnableDelayedExpansion
echo off
rem write header in output file
echo id;value> output.csv
rem remove the header of the file and loop
for /f "tokens=1,2 delims=;" %%A in ('more +1 my_file.csv') do (
set "result="
rem search if current id is in the temp list (tmp file) of processed ids
for /f "delims=" %%i in ('findstr /c:"%%A;" output.csv') do set result=!result!%%i
rem if the id is not in tmp file (the id is not yet processed)
if "!result!"=="" (
set sum=0
rem get all values related to the current id and calculate the sum
for /f "tokens=2 delims=;" %%V in ('findstr /c:"%%A;" my_file.csv') do (
set /a sum+=%%V
)
echo %%A;!sum!>> output.csv
)
)