[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 批处理怎样在一个文本中改变一列数字为任意数并求和?

有一个文本
========================================
xx东厂区污水处理回用工程生产日报表,,,,,,,,,,,,
,原水pH,原水SS,澄清水浊度,澄清水pH,滤后水浊度,回用水流量,原水流量,混凝剂药耗,聚合物药耗,石灰药耗,硫酸药耗,碳酸钠药耗
时间/单位,-,mg/l,NTU,-,NTU,m3,m3,kg,kg,kg,kg,kg
1,9.800000,65.000000,2.550000,8.270000,0.670000,0.000000,1500.000000,32.500000,0.402000,376.000000,52.600000,0.000000
2,9.740000,71.000000,2.200000,8.220000,0.670000,0.000000,1499.000000,32.600000,0.403000,375.000000,53.600000,0.000000
3,9.760000,72.000000,2.050000,8.210000,0.670000,0.000000,1500.000000,32.500000,0.402000,382.000000,49.500000,0.000000
4,9.800000,69.000000,2.330000,8.260000,0.680000,0.000000,1500.000000,32.600000,0.402000,375.000000,49.000000,0.000000
5,9.830000,65.000000,2.250000,8.230000,0.660000,0.000000,1500.000000,32.500000,0.403000,382.000000,49.900000,0.000000
6,9.870000,63.000000,1.910000,8.200000,0.660000,0.000000,1500.000000,32.500000,0.402000,376.000000,46.600000,0.000000
7,9.920000,61.000000,2.000000,8.280000,0.660000,0.000000,1500.000000,32.600000,0.402000,375.000000,46.200000,0.000000
8,9.960000,61.000000,2.030000,7.630000,0.650000,0.000000,1500.000000,32.500000,0.363000,382.000000,65.600000,0.000000
9,10.020000,74.000000,1.860000,8.140000,0.670000,0.000000,1311.000000,28.500000,0.354000,319.000000,38.400000,0.000000
10,10.010000,59.000000,1.920000,8.190000,0.650000,0.000000,1000.000000,21.800000,0.268000,231.000000,30.900000,0.000000
11,9.910000,43.000000,2.110000,8.230000,0.640000,0.000000,970.000000,21.100000,0.261000,227.000000,30.500000,0.000000
12,9.830000,34.000000,2.140000,8.150000,0.640000,0.000000,800.000000,17.400000,0.215000,201.000000,23.900000,0.000000
13,9.720000,30.000000,2.120000,8.220000,0.600000,0.000000,800.000000,17.400000,0.214000,203.000000,24.100000,0.000000
14,9.630000,25.000000,2.070000,8.260000,0.590000,0.000000,800.000000,17.300000,0.215000,204.000000,23.100000,0.000000
15,9.520000,43.000000,2.160000,7.620000,0.590000,0.000000,1043.000000,22.600000,0.282000,257.000000,21.900000,0.000000
16,9.480000,45.000000,4.850000,8.410000,0.580000,0.000000,1050.000000,22.800000,0.283000,230.000000,26.300000,0.000000
17,9.520000,53.000000,3.630000,7.990000,0.590000,0.000000,1229.000000,26.700000,0.330000,289.000000,30.000000,0.000000
18,9.510000,59.000000,3.310000,8.530000,0.620000,0.000000,1553.000000,33.700000,0.417000,395.000000,37.300000,0.000000
19,9.530000,49.000000,2.860000,8.250000,0.660000,0.000000,1500.000000,32.500000,0.403000,376.000000,44.500000,0.000000
20,9.590000,44.000000,2.810000,8.250000,0.680000,0.000000,1500.000000,32.600000,0.393000,381.000000,45.700000,0.000000
21,9.600000,43.000000,2.770000,8.250000,0.670000,0.000000,1500.000000,32.500000,0.402000,376.000000,46.500000,0.000000
22,9.570000,38.000000,2.590000,8.270000,0.660000,0.000000,1500.000000,32.600000,0.402000,376.000000,47.600000,0.000000
23,9.560000,38.000000,2.420000,8.290000,0.650000,0.000000,1637.000000,35.500000,0.440000,416.000000,52.200000,0.000000
24,9.620000,38.000000,2.370000,8.280000,0.630000,0.000000,1755.000000,38.100000,0.471000,440.000000,59.100000,0.000000
DAY,Average,Average,Average,Average,Average,Total,Total,Total,Total,Total,Total,Total
,9.720000,52.000000,2.470000,8.190000,0.640000,0.000000,31947.000000,693.400000,8.529000,7944.000000,995.000000,0.000000
=========================================
要把值为0那一列都改成680-820之间的随机数,并在最下面求和。请问该如何编写批处理,谢谢!!
我想了很长时间,不得要领啊!

[ 本帖最后由 aresk 于 2011-1-13 21:49 编辑 ]

  1. @echo off
  2. set "File=a.txt"
  3. SetLocal EnableDelayedExpansion
  4. (for /f "usebackq delims=" %%a in ("%File%") do (
  5.     if "%%~xa"==".000000" (
  6.         set var=%%~na
  7.         set /a n1 = 680 + !random! %% 141, Total_n1 += n1
  8.         set /a n2 = 680 + !random! %% 141, Total_n2 += n2
  9.         if "!var:~0,1!"=="," set /a n1 = Total_n1 - n1, n2 = Total_n2 - n2
  10.         for %%b in (!n1!) do (
  11.             set var=!var:,0.000000=,%%b.000000!
  12.             echo !var:~0,-1!!n2!.000000
  13.         )
  14.     ) else echo %%a
  15. )) > "%File%_.txt"
复制代码

TOP

给你个思路 先随即生成数字 然后替换 最后在相加
@echo off
:loop
set /a a=%random% %% 820
if %a% gtr 680 echo 随机数:%a%
goto loop  
pause
替换:
@echo off
setlocal enabledelayedexpansion
for /f "tokens=* delims= " %%i in (3.txt) do (
set str=%%i
echo !str:00000=你所指的变量!>>结果.txt
)

TOP

回复 2楼 的帖子

神马都是浮云。凤飞飞

TOP

说两个问题:
1、论坛出现在线等啊,急啊之类的标题有被锁帖的危险
2、楼主你是污水处理厂的吧,我是你主管部门,告诉你们,你们年度考核不合格,连数据都给我造假  :)开玩笑
菜鸟学批,一批一大批~~~~~~

TOP

返回列表