一批联合收割机CSV删除头 [英] Batch Combine CSV Remove Header

查看:102
本文介绍了一批联合收割机CSV删除头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有相同的标题多个CSV文件,我想他们在批量组合在一起,只保留一个头。任何想法?

I have multiple CSV files with the same header and I'm trying to combine them together in Batch and keep only a single header. Any ideas?

推荐答案

您可以使用更多+1 输出所有,但1号线。

You could use MORE +1 to output all but the 1st line.

>new.csv (
   type file1.csv
   more +1 file2.csv
   more +1 file3.csv
   REM etc.
)

显然可以调整线的数目根据需要在每个文件中跳过

Obviously you can adjust the number of lines to skip in each file as needed.

要结合所有的CSV文件在当前文件夹:
编辑:修改不使用新创建的CSV输出输入

To combine all csv files in the current folder: modified to not use newly created output csv as input

@echo off
setlocal
set first=1
>new.csv.tmp (
  for %%F in (*.csv) do (
    if defined first (
      type "%%F"
      set "first="
    ) else more +1 "%%F"
  )
)
move /y new.csv.tmp new.csv >nul

或者你可以使用FOR / F,以避免处理新创建的文件:

Or you could use FOR /F to avoid processing newly created file:

@echo off
setlocal
set first=1
>new.csv (
  for /f "eol=: delims=" %%F in ('dir /b /a-d *.csv') do (
    if defined first (
      type "%%F"
      set "first="
    ) else more +1 "%%F"
  )
)

显然,如果所有的CSV文件共享相同的格式,这是唯一有效的。

Obviously this is only effective if all the csv files share the same format.

编辑2015年7月30日: 有一些限制:


  • 标签字符将被转换成一个空格字符串

  • 每个CSV源文件必须少于64K行

这篇关于一批联合收割机CSV删除头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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