Computing.Net > Forums > Programming > merge / combine / append all .csv files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

merge / combine / append all .csv files

Reply to Message Icon

Name: Cannon
Date: August 26, 2009 at 10:56:48 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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:

COPY *.CSV ALL.CSV and
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?



Sponsored Link
Ads by Google

Response Number 1
Name: ricardo647
Date: August 26, 2009 at 22:23:11 Pacific
Reply:

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

:all2
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.


0

Response Number 2
Name: Cannon
Date: August 27, 2009 at 06:18:27 Pacific
Reply:

Thank you much for your assistance. My initial testing shows that it works.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Batch to edit contents of... Batch to find / delete fi...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: merge / combine / append all .csv files

batch file --> combining csv files www.computing.net/answers/programming/batch-file-combining-csv-files-/16551.html

zip all the .csv files in a folder www.computing.net/answers/programming/zip-all-the-csv-files-in-a-folder/16724.html

Move all the .csv files not in .txt www.computing.net/answers/programming/move-all-the-csv-files-not-in-txt/16740.html