LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 09-05-2009, 06:09 PM   #1
t.malarvizhi
LQ Newbie
 
Registered: Sep 2009
Posts: 2

Rep: Reputation: 0
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.
 
Old 09-05-2009, 07:28 PM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,596

Rep: Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570Reputation: 2570
Quote:
Originally Posted by t.malarvizhi View Post
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.
 
Old 09-05-2009, 07:37 PM   #3
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 09-06-2009, 10:26 PM   #4
travishein
LQ Newbie
 
Registered: Apr 2004
Location: Canada
Posts: 11

Rep: Reputation: 0
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.
 
Old 09-06-2009, 11:34 PM   #5
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
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.
 
Old 09-07-2009, 04:20 AM   #6
t.malarvizhi
LQ Newbie
 
Registered: Sep 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by travishein View Post
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 ??
 
  


Reply

Tags
creation, file, php


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
yum update PHP on CentOS - missing dependency php-common AndyMillne Linux - Server 7 05-21-2013 06:34 AM
php page displaying text that is supposed to be part of php code DragonM15 Programming 9 07-31-2008 04:58 PM
You have chosen to open index.php which is a : PHP Script from: http://localhost cucolin@ Linux - Software 3 01-30-2007 03:58 PM
php5 apache2 mysql4 don't work, php does not seem to read php.ini atom Linux - Software 5 03-24-2005 11:05 AM
php apache or php cgi - php learner rblampain Linux - Security 3 12-17-2004 11:10 PM


All times are GMT -5. The time now is 09:35 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration