LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP Help (https://www.linuxquestions.org/questions/programming-9/php-help-752970/)

t.malarvizhi 09-05-2009 06:09 PM

PHP Help
 
I want a script to split the large CSV file (more thans 50MB) into multiple CSV file of each not more than 9MB.

Anyone having script ... Help Me.

Thanks
Malar.

TB0ne 09-05-2009 07:28 PM

Quote:

Originally Posted by t.malarvizhi (Post 3671319)
I want a script to split the large CSV file (more thans 50MB) into multiple CSV file of each not more than 9MB.

Anyone having script ... Help Me.

Thanks
Malar.

Sure...post what you've written, and we'll be glad to help you. But we're not going to write your code for you....

Check php.net for a list of functions.

paulsm4 09-05-2009 07:37 PM

Also, there's a standard Unix command called "split" that might be exactly what you're looking for.

Type "man split", or Google "linux split command" for details.

Good luck .. PSM

travishein 09-06-2009 10:26 PM

The challenge is approximating size of file, depending on how much data is on a single line of the input CSV, will determine how many lines get copied to each output file.

Since CSV files are mostly single line per record, line oriented, you could try reading the input file, copying the character out to the 'current' output file, say out_1.csv, while building a count of characters read.

On reading each new line evaluate if the character size read so far has exceeded the desired size of output file. If so, close the file and open a new out_2.csv and repeat until no more input file.

Wim Sturkenboom 09-06-2009 11:34 PM

http://www.php.net/manual-lookup.php?pattern=csv reveals:

fputcsv
fgetcsv
str_getcsv

Never used them but it sounds like they will do the trick. Please pay attention to the version of PHP required for each of the above functions.

t.malarvizhi 09-07-2009 04:20 AM

Quote:

Originally Posted by travishein (Post 3672448)
The challenge is approximating size of file, depending on how much data is on a single line of the input CSV, will determine how many lines get copied to each output file.

Since CSV files are mostly single line per record, line oriented, you could try reading the input file, copying the character out to the 'current' output file, say out_1.csv, while building a count of characters read.

On reading each new line evaluate if the character size read so far has exceeded the desired size of output file. If so, close the file and open a new out_2.csv and repeat until no more input file.

How can we get the Character size ??


All times are GMT -5. The time now is 04:41 PM.