0

I have large CSV multiple file say 20-30mb which has same header however the number rows of those files are different. I need a batch file which will copy the content of all the CSV file in one excel sheet.

Hope you guys will help me in creating a batch file please.. I tried creating macros but ends with wrong or improper data. kindly help me please

2
  • type *.csv >newfile.csv & newfile.csv ? Commented Nov 30, 2013 at 18:52
  • hi stephan, i tried this but it is copying the headers of all the files..as the headers are same so i want one single sheet with header and contents of files..hope u understood... Commented Nov 30, 2013 at 18:58

3 Answers 3

1
for %%a in (*.txt) do @type %%a|find /v "Header line" >newfile.csv
rem open in excel:
newfile.csv
Sign up to request clarification or add additional context in comments.

Comments

0

If the CSV files have less than 65K lines in them then this will work:

The final CSV file can have more than 65K lines.

@echo off
set "flag="
for %%a in (*.csv) do (
   if not defined flag (
      copy "%%a" temp.tmp & set flag=1
    ) else (
      more +2 "%%a" >>temp.tmp
    )
)
ren temp.tmp "newfile.csv"

Comments

0
@echo off
for %%a in (*.csv) do set /P "header=" < "%%a" & goto continue
:continue
(
echo %header%
for %%a in (*.csv) do findstr /V /C:"%header%" < "%%a"
) > large.txt
ren large.txt large.csv

EDIT: Below there is an example of what this program do:

C:\Users\Antonio\Documents
>type file1.csv
Common header for all files
File One line one
File One line two
File One line three

C:\Users\Antonio\Documents
>type file2.csv
Common header for all files
File Two line one
File Two line two
File Two line three

C:\Users\Antonio\Documents
>type file3.csv
Common header for all files
File Three line one
File Three line two
File Three line three

C:\Users\Antonio\Documents
>test

C:\Users\Antonio\Documents
>type large.csv
Common header for all files
File One line one
File One line two
File One line three
File Two line one
File Two line two
File Two line three
File Three line one
File Three line two
File Three line three

2 Comments

hi all, the above all code is not working..could you please help me with more suggestions...
See the added example above. What exactly you mean with "is not working"? Got you errors? Got you wrong result?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.