批处理文件,使用NO 3rd Party Apps将文本文件拆分为Win Svr 2012上同一目录中的多个文件 [英] Batch file to split text file into multiple files in same directory on Win Svr 2012 using NO 3rd Party Apps

查看:105
本文介绍了批处理文件,使用NO 3rd Party Apps将文本文件拆分为Win Svr 2012上同一目录中的多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这里的专家能为我解决问题.我发现该站点过去在解决我遇到的其他问题方面非常有用,但是我已经搜索了该站点并尝试了所有与我的问题类似的答案,但似乎无法让他们中的任何一个适用于该特定问题.我不是编码人员,但已经涉猎其他代码,并让他们为其他问题工作.

I am hoping the wonderful experts here can assist me with my problem. I have found this site extremely useful in the past in solving other issues I have had but I have searched this site and tried all the answers similar to my problem but cant seem to get any of them to work for this particular problem. I am not a coder but have dabbled with other code and got them to work for other issues.

我需要将包含关键字(每行1 kw,无空行)的文本文件拆分到同一目录中的多个文本文件中,每个文本文件包含300行(如果最后的文本文件的总输入行数不能被300整除,则最后一个文本文件除外) .输入文件永远不会大于100MB.

I need to split a text file containing keywords(1 kw per line, no blank lines) into multiple text files within the same directory, each with 300 lines (except last text file if total input lines not exactly divisible by 300). The input file will NEVER be larger than 100MB.

理想情况下,然后我将输入文件拆分后将其删除,并将所有拆分的文本文件移至另一个目录(原始目录中没有其他文本文件可担心),然后将其删除 我需要它是一个bat文件或通过bat文件调用的vbs脚本.

Ideally, I then need the input file deleted once it has been split and all split text files moved to another directory (there are no other text files to worry about in the original directory) I need it to be a bat file or vbs script called via bat file.

输入文件:

  • keyword-file.txt

输出文件:

  • keyword-file_1.txt(300行)
  • keyword-file_2.txt(300行)
  • keyword-file_3.txt(300行)

为澄清以上要求:

  1. 将输入文本文件(<100MB)拆分为较小的文本文件,每行300行
  2. 删除输入文本文件
  3. 将所有拆分的文本文件移动到另一个指定的目录

推荐答案

对于拆分,也许可以这样做:

For the splitting, perhaps something like this will do:

@Echo Off
Setlocal EnableExtensions DisableDelayedExpansion

Set "inFile=keyword-file.txt"
Set "nLines=300"

If Not Exist "%inFile%" GoTo :EOF
For %%A In ("%inFile%") Do Set "fName=%%~nA"&Set "fExt=%%~xA"

Set "count=0"
For /F %%A In ('Find /C /V ""^<"%inFile%"') Do Set "fLines=%%A"

(For /L %%A In (1 1 %fLines%) Do (Set/P "data="
    Set/A "file=(count/%nLines%)+1", "count+=1"
    SetLocal EnableDelayedExpansion
    (Echo=!data!)>>"%fName%_!file!%fExt%"
    EndLocal))<"%inFile%"

EndLocal
GoTo :EOF

我将保留删除内容并将命令移给您……

这篇关于批处理文件,使用NO 3rd Party Apps将文本文件拆分为Win Svr 2012上同一目录中的多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆