尝试输出文件名,记录计数,对L列的csv进行排序,并替换目录中每个csv的第一个记录全名和最后一个记录全名。
我正在尝试打印出包含zip,名字,姓氏的数组。我的脚本的逻辑是读取源csv的特定列。我能够输出文件名和记录计数。但是我可以看到获得正确的第一条记录全名和最后一条记录全名。从我的样本数据中可以看到,有重复。
示例:
Filename: Test1.csv Record Count: 988 First Record Name: 12025, Jeff, Meacham Last Record Name: 14905, Jazzlynn, Doe Filename: Test2.csv Record Count: 580 First Record Name: 12010, Jim, Palmerino Last Record Name: 14905, Jazzlynn, Doe Filename: Test3.csv Record Count: 522 First Record Name: 12010, Jim, Palmerino Last Record Name: 14905, Joseph, Panosian Filename: Test4.csv Record Count: 555 First Record Name: 12010, jim, Palmerino Last Record Name: 14905, Joseph, Thurber
@ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
IF EXIST result3.txt DEL /F result3.txt
for %%f in (*csv) do (
set CurrentFile=%%f
set /a NumLines=0
for /f %%j in ('Find "" /v /c ^< !CurrentFile!') Do (
Set /a NumLines=%%j
)
for /F "tokens=1-12 delims=," %%a in (!CurrentFile!) do (
if not defined counter set counter=0
set /a counter+=1
set line[%%~lcounter]=%%l, %%d, %%f
)
(set row=%~1) & (set last=%~1)
for /F "tokens=1-2 delims==" %%a in ('set line[') do (
if not defined row (set row=%%b ) else (set last=%%b )
set row=!row:"=!
set last=!last:"=!
)
echo.
echo. Filename: !CurrentFile!
echo. Record Count: !NumLines!
echo. First Record Name: !row!
echo. Last Record Name: !last!
) >> result3.txt
)
ENDLOCAL
Filename: Test1.csv Record Count: 988 First Record Name: 12025, Jeff, Meacham Last Record Name: 14905, Jazzlynn, Doe Filename: Test2.csv Record Count: 580 First Record Name: 12010, Jim, Palmerino Last Record Name: 14905, Matthew Smalles Filename: Test3.csv Record Count: 522 First Record Name: 12010, Joshua Long Last Record Name: 14905, Joseph, Panosian Filename: Test4.csv Record Count: 555 First Record Name: 12010, Hillary Koller Last Record Name: 14905, Joseph, Thurber
答案 0 :(得分:0)
我通过将当前文件名添加到数组名来解决了该问题。从而每次创建一个新数组。 ('设置line_!CurrentFile![')