批处理文件拆分.csv文件 [英] Batch file to split .csv file

查看:2175
本文介绍了批处理文件拆分.csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的.csv文件(> 500MB),我希望打破这一成成更小的.csv文件中的命令提示符。 (基本上是试图找到一个Linux的分割功能在Windows。

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".

这已经是一个批处理脚本作为我的机器只安装了窗户,并要求软件是一种痛苦。我碰到了一些样品codeS来到(<一个href=\"http://forums.techguy.org/software-development/1023949-split-100000-line-csv-into.html\">http://forums.techguy.org/software-development/1023949-split-100000-line-csv-into.html),然而,当我执行批处理这是行不通的。我得到的是,只有125KB,当我要求它每20万行解析一个输出文件。

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 (http://forums.techguy.org/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
)

由于在code上面显示,将原来的CSV文件分成多个CSV文件分割为20万行的限制。所有你需要做的是改变!文件!!极限!变量相应。希望它帮助。

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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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