merge / combine / append all .csv files

August 26, 2009 at 10:56:48
Specs: Windows XP
I need a Batch file that will merge / combine / append all the .CSV files in the current directory together with only one header row. The header row is the same in each file and is the first row of each file.

I have tried the following:

FOR %%1 in (*.CSV) do type %%1 >> ALL.CSV

How can I add the first file as it is and then add all the others to it without the first row?

See More: merge / combine / append all .csv files

Report •

August 26, 2009 at 22:23:11
Try this:

setlocal enabledelayedexpansion
@echo off
del all.csv
set header=abcd
::change the content of header, above

for %%a in (*.csv) do type "%%a">>all.tmp
echo %header%>ALL.CSV

for /f "tokens=1,* delims=" %%b in (all.tmp) do (
set x=%%b
call :all2
del all.tmp
goto :eof

for /f "tokens=1,* delims=" %%c in ("!x!") do set y=%%c
if !y!==!header! goto :eof
echo !y! >> ALL.CSV
goto :eof

Caution: any line identical to header will also be ignored.

Report •

August 27, 2009 at 06:18:27
Thank you much for your assistance. My initial testing shows that it works.

Report •

Related Solutions

Ask Question