Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
09-05-2009, 06:09 PM
|
#1
|
|
LQ Newbie
Registered: Sep 2009
Posts: 2
Rep:
|
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.
|
|
|
|
09-05-2009, 07:28 PM
|
#2
|
|
Guru
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 11,817
|
Quote:
Originally Posted by t.malarvizhi
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.
|
|
|
|
09-05-2009, 07:37 PM
|
#3
|
|
Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,861
Rep: 
|
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
|
|
|
|
09-06-2009, 10:26 PM
|
#4
|
|
LQ Newbie
Registered: Apr 2004
Location: Canada
Posts: 11
Rep:
|
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.
|
|
|
|
09-06-2009, 11:34 PM
|
#5
|
|
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,780
|
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.
|
|
|
|
09-07-2009, 04:20 AM
|
#6
|
|
LQ Newbie
Registered: Sep 2009
Posts: 2
Original Poster
Rep:
|
Quote:
Originally Posted by travishein
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 ??
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:17 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|