用于拆分 .csv 文件的批处理文件

编程入门 行业动态 更新时间:2024-10-27 03:36:52
本文介绍了用于拆分 .csv 文件的批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个非常大的 .csv 文件 (>500mb),我希望在命令提示符下将其分解为较小的 .csv 文件.(基本上是试图在Windows中找到一个linux拆分"功能.

I have a very large .csv file (>500mb) and I wish to break this up into into smaller .csv files in command prompt. (Basically trying to find a linux "split" function in Windows".

这必须是一个批处理脚本,因为我的机器只安装了 Windows,请求软件很麻烦.我遇到了一些示例代码(forums.techguy/software-development/1023949-split-100000-line-csv-into.html),但是,当我执行批处理时它不起作用.当我要求它每 20 000 行解析一次时,我得到的只是一个只有 125kb 的输出文件.

This has to be a batch script as my machine only has windows installed and requesting softwares is a pain. I came across a number of sample codes (forums.techguy/software-development/1023949-split-100000-line-csv-into.html), however, it does not work when I execute the batch. All I get is one output file that is only 125kb when I requested it to parse every 20 000 lines.

有没有人遇到过类似的问题,你们是如何解决这个问题的?

Has anyone ever come across a similar problem and how did you resolve the issue?

推荐答案

试试这个:

@echo off setLocal EnableDelayedExpansion set limit=20000 set file=export.csv set lineCounter=1 set filenameCounter=1 set name= set extension= for %%a in (%file%) do ( set "name=%%~na" set "extension=%%~xa" ) for /f "tokens=*" %%a in (%file%) do ( set splitFile=!name!-part!filenameCounter!!extension! if !lineCounter! gtr !limit! ( set /a filenameCounter=!filenameCounter! + 1 set lineCounter=1 echo Created !splitFile!. ) echo %%a>> !splitFile! set /a lineCounter=!lineCounter! + 1 )

如上面的代码所示,它将原始csv文件拆分为多个csv文件,限制为20 000行.您所要做的就是相应地更改 !file! 和 !limit! 变量.希望能帮助到你.

As shown in the code above, it will split the original csv file into multiple csv file with a limit of 20 000 lines. All you have to do is to change the !file! and !limit! variable accordingly. Hope it helps.

更多推荐

用于拆分 .csv 文件的批处理文件

本文发布于:2023-05-27 19:33:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/300585.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:批处理文件   文件   csv

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!