Batch Combine CSV Remove Header Batch Combine CSV Remove Header windows windows

Batch Combine CSV Remove Header


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.

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

@echo offsetlocalset first=1>new.csv.tmp (  for %%F in (*.csv) do (    if defined first (      type "%%F"      set "first="    ) else more +1 "%%F"  ))ren new.csv.tmp new.csv

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

EDIT 2015-07-30: There are some limitations:

  • Tab characters will be converted into a string of spaces
  • Each CSV source file must have fewer than 64k lines


I was having issues with dbenham's method for combining all CSV files in the current folder. It would occasionally pick up the resulting CSV and include it in the set. I have modified it to avoid this problem.

@echo offsetlocalset first=1set fileName="combinedFiles.csv">%fileName% (  for %%F in (*.csv) do (    if not "%%F"==%fileName% (      if defined first (        type "%%F"        set "first="      ) else more +1 "%%F"    )  ))


It didn't work for me since my files have >200k rows (read from another post it works for file <64k rows). I modified the script to use sed to print the rows instead.

-n : quiet, suppress automatic printing of all rows

1,$: first row till last row

p : print row that matches pattern

@echo offsetlocalset first=1set fileName="combinedFiles.csv">%fileName% (  for %%F in (*.csv) do (    if not "%%F"==%fileName% (      if defined first (        sed -n 1,$p "%%F"        set "first="      ) else sed -n 2,$p "%%F"    )  ))