- @echo off
- setlocal EnableDelayedExpansion
- set /a rowStart=37
- set /a rowEnd=39
- set /a colNumber=4
- set "fileSeperator=,"
- set "fileType=csv"
-
- if "!fileType!"=="csv" (
- set "allFile=*.csv"
- ) else (
- set "allFile=*.txt"
- )
- if "!fileSeperator!"=="," (
- set outputFile=new.csv
- ) else (
- set outputFile=new.txt
- )
- set /a fileCount=!rowEnd!-!rowStart!+1
- for /l %%a in (!rowStart!,1,!rowEnd!) do (
- set /a fileNumber=%%a-!rowStart!+1
- set /a skip=0
- for /f "delims=" %%b in ('dir /b !allFile!') do (
- for /f "tokens=%colNumber% delims=," %%c in ('type %%b') do (
- set /a skip+=1
- if "!skip!"=="%%a" (
- echo %%c>>file!fileNumber!.txt
- )
- )
- set /a skip=0
- )
- )
- set /a n=!fileCount!
- set /a m=0
- set str=
- type nul>!outputFile!
- for /l %%a in (1,1,!n!) do (
- set /a n1=0
- for /f %%b in ('type file%%a.txt') do (
- set /a n1+=1
- for /l %%c in (!n1!,1,!n1!) do (
- set file%%a.row%%c=%%b
- )
- )
- if !n1! gtr !m! (set /a m=!n1!)
- )
- for /l %%a in (1,1,!m!) do (
- for /l %%b in (1,1,!n!) do (
- if "!file%%b.row%%a!"=="" (set /a file%%b.row%%a=0)
- if "%%b"=="!n!" (
- set "str=!str!!file%%b.row%%a!"
- ) else (
- if "!fileSeperator!"=="," (
- set "str=!str!!file%%b.row%%a!,"
- ) else (
- set "str=!str!!file%%b.row%%a! "
- )
- )
- )
- echo !str!>>!outputFile!
- set str=
- )
- for /l %%a in (1,1,!fileCount!) do (
- if exist ".\file%%a.txt" del ".\file%%a.txt"
- )
复制代码 这个稍稍通用一点 |