Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 在bat文件中编辑字符串_Windows_Batch File - Fatal编程技术网

Windows 在bat文件中编辑字符串

Windows 在bat文件中编辑字符串,windows,batch-file,Windows,Batch File,我有一个bat文件,它读取记录列表并从每一行提取一个数字。然后,它将这些数字写入另一个文本文件,从这里开始计算,以查看总值,在读取数字时删除前导的0 这一切都很好,但我似乎不能得到正确的是,因为这个值是一个价格,它需要有2个小数点。目前,它作为2971480打印到文件中,但我需要它作为29714.80打印。有没有办法在bat文件中这样做 我使用的代码如下所示: setlocal EnableDelayedExpansion rem.> "C:\output.txt" for /F "del

我有一个bat文件,它读取记录列表并从每一行提取一个数字。然后,它将这些数字写入另一个文本文件,从这里开始计算,以查看总值,在读取数字时删除前导的0

这一切都很好,但我似乎不能得到正确的是,因为这个值是一个价格,它需要有2个小数点。目前,它作为
2971480
打印到文件中,但我需要它作为
29714.80
打印。有没有办法在bat文件中这样做

我使用的代码如下所示:

setlocal EnableDelayedExpansion
rem.> "C:\output.txt"
for /F "delims=" %%L in ('findstr /L "T" "C:\test files\test.txt"') do (
set "LINE=%%L" & set "LINE=!LINE:*ResponseCode=!" & echo !LINE:~39,8%!
)>> "C:\output.txt"
endlocal
set sum=0
cd C:\test files
for /F "tokens=* delims=0" %%A in (output.txt) do set /a sum=sum+%%A
echo The total Sales for today was %sum% > output2.txt
output2.txt
pause
我真的不知道该怎么办。任何帮助都将不胜感激

编辑

原始文件如下所示:

“59”,003005213,23,100017,07,590000000,0303005213,04000000000000000000000000000000000000000000000,“R”,00000000 “59”,00209205,23,100017,08,0000010000,020009205,0200001000000000000000043000000000000004300000005000000000000000000000000000000000000000000700,“R”,00000000 “61”,000000000 187900000100,10000043000004300,02,01,0,“T”,002009205,0 “59”,002009206,23,100017,08,02000010000,020009206,02000010000000000120000000001200000000012000000000120000001200000000000000000000000000000000000000000000000000000000000000000000,“R”,00000000 “61”,000000000 14300000001,10000120001200,02,01,0,“T”,002009206,0 “59”,003005214,23,100017,08,0300010000,0303005214,02000010000000000650000000650000000650000000000000000000,“R”,00000000 “61”,000000000 142800000005,100001300000006500,02,01,0,“T”,003005214,0 “59”,002009207,23,100017,08,0400020000,020009207,02000020000360000000000000000000360000005000000000000000000000000000000000001400,“R”,00000000 “61”,0000000000 285000001,100002800002800,02,00,0,“T”,002009207,0 “61”,0000000000 43000000002,1000040000000800,02,00,0,“T”,002009207,0 “59”,003005215,23,100017,08,0700000000,0303005215,04000000000000000000000000000000000000000,“R”,00000000 “59”,003005216,23,100017,08,0900000000,0303005216,04000000000000000000000000000000000000000000000,“R”,00000000 “59”,002009208,23,100017,08,100001000000,020009208,020000100007000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000003000,“R”,00000000 “61”,0000000000 3370000001,100007000007000,02,00,0,“T”,002009208,0 “59”,003005217,23,100017,08,100001000000,0303005217,02000010000000000650000000650000000650000000000000000000,“R”,00000000 “61”,000000000 142800000005,100001300000006500,02,01,0,“T”,003005217,0

每行以61或59开头

然后在过滤器之后:

00004300 00001200 00006500 00002800 00000800 00007000 00006500 00002900 00000400 00003250 00000520 00002990 00003250 00001300 00005040 00000470 00000410 00002600 00017000 00002800 00001575 00006500 00002430 00001615 00002150 00000350 00001300 00001435 00006500 00002600 00003250 00001860 00003250 00002985 00000430 00001200 00000860 00000515 00002350 00001300 00001300 00001005 00000865 00000430 00002200 00006500 00002490 00001985 00001300 00013000 00001300 00006500 00001300 00006500 00006500 00001300 00003250 00003925 00001160 00002800 00006500 00002200 00001300 00000430 00003250 00000615 00013000 00005490 00002600 00002510 00001300 00008445 00003250 00004595 00013000 00001000 00001005 00001300 00006500 00001300 00001300 00003255 00000670 00002600 00004400 00002480 00001490 00001950 00002895 00003120 00003525 00003250 00005660 00013000 00001470 00006500 00010810 00003250 00003870 00000550 00000400 00001460 00003250 00001300 00000430 00003250 00000430 00007000 00007165 00026000 00003250 00002445 00006500 00003890 00003390 00003250 00002800 00002395 00005555 00002970 00002700 00003445 00003150 00001520 00000930 00010205 00002945 00003250 00001120 00006500 00001215 00006500 00001980 00001495 00002040 00000400 00003250 00000220 00006500 00003250 00006140 00002600 00009750 00000525 00002405 00001920 00000995 00000430 00000430 00006500 00001965 00006500 00001070 00000810 00000430 00017000 00000485 00002010 00006500 00001105 00003480 00003250 00003250 00010025 00000510 00003250 00007000 00003250 00002320 00006500 00002600 00000650 00010345 00005340 00002995 00001240 00003250 00001005 00006500 00001015 00003250 00005065 00000430 00000580 00000450 00000860 00004550 00000430 00001300 00010560 00000880 00000465 00006500 00000840 00003250 00006060 00002600 00010625 00003250 00000430 00000920 00000930 00002600 00005245 00001300

然后我把它们加在一起,去掉前导的零,得到最终的总数

echo The total Sales for today was %sum:~0,-2%.%sum:~-2% > output2.txt

也就是说,输出
sum
,除了最后2个字符和一个点,然后是最后2个字符。

您也可以显示一个示例输入文件吗?当我运行此操作时,我的输出打印%sum:0,-2%。%sum:~-2%,而不是我遗漏了一个
~/code>的数字。