windows - 批处理文件存储行变量并对它们求和

标签 windows for-loop batch-file cmd

我的输入文件 Count.txt 包含以下内容:

] /Count 1
] /Count 2

我试图在每一行的末尾添加数字字符并将其存储到另一个文件或将其存储到另一个变量。 我无法使用以下批处理文件脚本执行此操作:

setlocal enabledelayedexpansion
set count=0
for /f "tokens=3 delims= " %%i in ('findstr Count Count.txt') do (
set /a count=%%i + %count%
echo !count! > finalcount.txt
) 
endlocal

我得到的输出是 2。

请帮忙。

最佳答案

试试这个:

@echo off &setlocal enabledelayedexpansion
set count=0

(for /f "tokens=3" %%i in ('findstr "Count" Count.txt') do (
set /a count+=%%i
echo !count! 
))> finalcount.txt

关于windows - 批处理文件存储行变量并对它们求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18141753/

相关文章:

c++ - _beginthread/ex C3861 - 找不到标识符

windows - 在特定 CPU 负载下运行程序的脚本

windows - 批处理文件 - 命令的语法不正确

ios - 为什么我会收到此错误 : fatal error - array index out of range?

batch-file - Windows 批处理文件为输入的年份中的每个日期创建文件夹并支持闰年

shell - 我想同时在多个浏览器中打开一个链接进行测试

windows - DigitalProductId 和 InstallDate 会改变吗?

python - 如何切片生成器对象或迭代器?

c - c != '\n'条件在 "for"循环中的作用是什么(C语言)?

Windows 使用代理从 URL 批量下载文件