要处理的temp3.csv的数据如下:
,c1 ,c2 ,c3 ,c4 ,c5 ,c6 ,c7 ,c8 ,c9 ,c10
,1,2,3,4,5,6,7,8,9,10
,11,12,13,14,15,16,17,18,19,20
,21,22,23,24,25,26,27,28,29,30
,31,32,33,34,35,36,37,38,39,40
,41,42,43,44,45,46,47,48,49,50
,51,52,53,54,55,56,57,58,59,60
,61,62,63,64,65,66,67,68,69,70
,71,72,73,74,75,76,77,78,79,80
,81,82,83,84,85,86,87,88,89,90
,91,92,93,94,95,96,97,98,99,100
编写了如下批处程序:
@echo off
if not exist temp3.csv echo "temp3.csv has not generated, please run program above :next" && pause
setlocal enabledelayedexpansion
if exist *.txt del *.txt
REM --------------------------------------------
REM extracting the first row of temp.csv
REM --------------------------------------------
for /L %%k in (1,1,6) do (
set iter=%%k
set line=0
(for /f "tokens=*" %%a in (temp3.csv) do (
set /a line+=1
set numb=0
for %%i in (%%a) do (
REM --------------------------------------------
REM extracting the name for comparision
REM --------------------------------------------
set /a numb+=1
if !line!==1 if !numb!==!iter! set name=%%i
if !numb!==!iter! echo %%i
)
))>!name!.txt
)
但是结果出现了:
.txt
c1.txt
c2.txt
c3.txt
c4.txt
c5.txt
为什么会出现.txt?而不是c1.txt,显示都向后面滞后了一位。我用程序核实了.txt这个循环中的name取值,其值的确是c1。但是不知在>!name!.txt文献输出的时候,所有的取值都向后滞后了一位。有没有高手帮助解释一下原因,多谢多谢! |