@echo off for /f "tokens=1*delims=:" %%a in ('findstr /n "^" "PASSWORD.txt"') do for /f "delims=~" %%c in ("%%~b") do >"text%%a.txt" echo(%%c pause
它的工作原理,但它逐行分割。 我如何让它每5000行分割一次。 提前致谢。
编辑:
I have just tried this: @echo off setlocal ENABLEDELAYEDEXPANSION REM Edit this value to change the name of the file that needs splitting. Include the extension. SET BFN=passwordAll.txt REM Edit this value to change the number of lines per file. SET LPF=50000 REM Edit this value to change the name of each short file. It will be followed by a number indicating where it is in the list. SET SFN=SplitFile REM Do not change beyond this line. SET SFX=%BFN:~-3% SET /A LineNum=0 SET /A FileNum=1 For /F "delims==" %%l in (%BFN%) Do ( SET /A LineNum+=1 echo %%l >> %sFN%!FileNum!.%sFX% if !LineNum! EQU !LPF! ( SET /A LineNum=0 SET /A FileNum+=1 ) ) endlocal Pause exit
但我得到一个错误说: Not enough storage is available to process this command
文件deleteOnExit()函数保持参考指针打开,即使文件被删除后
以编程方式确定video文件格式?
读/写Windows图像标签(关键字)
在c#中读取扩展图像属性
关于Vim的三个问题
在数据库中存储Windowspath并使用java检索Hibernate
如何比较Linux中的两个大文件?
如何检查是否可以创build给定长度的文件?
使用remove函数删除的文件在移除之后立即在FindFirstFile / FindNextFile循环中显示出来。 为什么是这样?
这会给你一个基本的骨架。 根据需要调整
@echo off setlocal enableextensions disabledelayedexpansion set "nLines=5000" set "line=0" for /f "usebackq delims=" %%a in ("passwords.txt") do ( set /a "file=line/%nLines%","line+=1" setlocal enabledelayedexpansion for %%b in (!file!) do ( endlocal >>"passwords_%%b.txt" echo(%%a ) ) endlocal
EDITED
正如评论所示,一个4.3GB的文件很难管理。 for /f需要将完整的文件加载到内存中,并且所需的缓冲区是该大小的两倍,因为该文件在内存中被转换为unicode。
这是一个完全临时的解决方案。 我没有测试过它的文件,但至少在理论上它应该工作(除非5000行需要大量的内存,这取决于行长度)
而且,用这样的文件,它会很慢
@echo off setlocal enableextensions disabledelayedexpansion set "line=0" set "tempFile=%temp%passwords.tmp" findstr /n "^" passwords.txt > "%tempFile%" for /f %%a in ('type passwords.txt ^| find /c /v "" ') do set /a "nFiles=%%a/5000" for /l %%a in (0 1 %nFiles%) do ( set /a "e1=%%a*5","e2=e1+1","e3=e2+1","e4=e3+1","e5=e4+1" setlocal enabledelayedexpansion if %%a equ 0 ( set "e=/c:"[1-9]:" /c:"[1-9][0-9]:" /c:"[1-9][0-9][0-9]:" /c:"!e2![0-9][0-9][0-9]:" /c:"!e3![0-9][0-9][0-9]:" /c:"!e4![0-9][0-9][0-9]:" /c:"!e5![0-9][0-9][0-9]:" " ) else ( set "e=/c:"!e1![0-9][0-9][0-9]:" /c:"!e2![0-9][0-9][0-9]:" /c:"!e3![0-9][0-9][0-9]:" /c:"!e4![0-9][0-9][0-9]:" /c:"!e5![0-9][0-9][0-9]:" " ) for /f "delims=" %%e in ("!e!") do ( endlocal & (for /f "tokens=1,* delims=:" %%b in ('findstr /r /b %%e "%tempFile%"') do @echo(%%c)>passwords_%%a.txt ) ) del "%tempFile%" >nul 2>nul endlocal
再次编辑 :以前的代码将不能正确的工作,以冒号开头的行,因为它已被用作for命令中的分隔符来分隔行号和数据。
对于另一个选择,仍然是纯批次,但仍然很慢
@echo off setlocal enableextensions disabledelayedexpansion set "nLines=5000" set "line=0" for /f %%a in ('type passwords.txt^|find /c /v ""') do set "fileLines=%%a" < "passwords.txt" (for /l %%a in (1 1 %fileLines%) do ( set /p "data=" set /a "file=line/%nLines%","line+=1" setlocal enabledelayedexpansion >>"passwords_!file!.txt" echo(!data! endlocal )) endlocal
测试一下:输入文件是"file.txt" ,输出文件是"splitfile-5000.txt" 。
这使用一个名为findrepl.bat的帮助程序批处理文件 – 从以下网址下载: https : findrepl.bat
将findrepl.bat放在与批处理文件相同的文件夹中或路径中。
@echo off :: splits file.txt into 5000 line chunks. set chunks=5000 set /as=1-chunks :loop set /as=s+chunks set /ae=s+chunks-1 echo %s% to %e% call findrepl /o:%s%:%e% <"file.txt" >"splitfile-%e%.txt" for %%b in ("splitfile-%e%.txt") do (if %%~zb EQU 0 del "splitfile-%e%.txt" & goto :done) goto :loop :done pause
一个限制是文件中的行数,实际最大的数字是2^31 - 1批量数学最高的地方。
@echo off setlocal EnableDelayedExpansion findstr /N "^" PASSWORD.txt > temp.txt set part=0 call :splitFile < temp.txt del temp.txt goto :EOF :splitFile set /A part+=1 (for /L %%i in (1,1,5000) do ( set "line=" set /P line= if defined line echo(!line:*:=! )) > text%part%.txt if defined line goto splitFile exit /B
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。