Share via


split large csv file to many csv files

Question

Saturday, August 1, 2015 7:51 AM

Hi,

according i have a large csv file, i would like to split it into many litles csv files

how ?

best regards

All replies (4)

Saturday, August 1, 2015 2:43 PM âś…Answered

@logcorner    TIMTOWTDI

The second part of the article below will help you to create multiple files; the first part should give you some generic ideas too.

Basically, this MSDN article takes two separate text files and builds a third file which is then split into multiple files.

https://msdn.microsoft.com/en-us/library/bb546143.aspx "How to: Split a File Into Many Files by Using Groups (LINQ)"

the main difference is that you simply will read 100 lines at a time and then write a file; read another 100 rows, write a file.

when you hit end of file, even if you do not have 100 lines, you'll write what you have left over.

in pseudo code (not necessarily 100% correct):

while not end of file
   counter = 0
   while counter < 100
       if counter = 0 start new file
       read line; write to file
       counter++
       if counter == 100 {close file; counter ==0}
   end while
end while
if counter > 0 && counter < 100 close last file

Saturday, August 1, 2015 9:48 AM

What do you need help with?  What have you done so far?  Do you want to do this once or many times?  What is the split criteria?  Do you want to split horizontally or vertically?

You could open the file in Notepad, cut the rows out that you want and paste them into another Notepad session.  Repeat until finished.


Saturday, August 1, 2015 12:59 PM

I would like do it at runtime.

I would like to split horizontally,

retrieve 100 rows,

100 rows again

and so, until finish,

best regards


Sunday, August 2, 2015 2:20 AM

What do you need help with?  You have basically outlined the program yourself, where do you have a problem?

Have you ever written a program before?  Do you know what a variable is?  Do you know how to open, read, write to a file?  Do you have Visual Studio?  Do you need help installing it?  Do you have any code so far?  Are you stuck at some point?