LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
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

Tags used in this thread
Popular LQ Tags , ,

Reply
 
Thread Tools
Old 09-05-2009, 07:09 PM   #1
t.malarvizhi
LQ Newbie
 
Registered: Sep 2009
Posts: 2
Thanked: 0
PHP Help


[Log in to get rid of this advertisement]
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.
windows_xp_2003 t.malarvizhi is offline  
Tag This Post , ,
Reply With Quote
Old 09-05-2009, 08:28 PM   #2
TB0ne
Senior Member
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, Mandrake, RedHat, Gentoo, Slack
Posts: 4,065
Thanked: 142
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.
windows_xp_2003 TB0ne is offline     Reply With Quote
Old 09-05-2009, 08:37 PM   #3
paulsm4
Senior Member
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 3,316
Thanked: 144
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
paulsm4 is offline     Reply With Quote
Old 09-06-2009, 11:26 PM   #4
travishein
LQ Newbie
 
Registered: Apr 2004
Location: Canada
Posts: 10
Thanked: 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.
linuxubuntu travishein is offline     Reply With Quote
Old 09-07-2009, 12:34 AM   #5
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 8.04 (upgraded from 6.06), Ubuntu Netbook Remix 9.04
Posts: 2,741
Thanked: 87
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.
windows_xp_2003 Wim Sturkenboom is offline     Reply With Quote
Old 09-07-2009, 05:20 AM   #6
t.malarvizhi
LQ Newbie
 
Registered: Sep 2009
Posts: 2
Thanked: 0

Original Poster
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 ??
windows_xp_2003 t.malarvizhi is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 6 07-21-2009 06:10 PM
php page displaying text that is supposed to be part of php code DragonM15 Programming 9 07-31-2008 05:58 PM
You have chosen to open index.php which is a : PHP Script from: http://localhost cucolin@ Linux - Software 3 01-30-2007 04:58 PM
php5 apache2 mysql4 don't work, php does not seem to read php.ini atom Linux - Software 5 03-24-2005 12:05 PM
php apache or php cgi - php learner rblampain Linux - Security 3 12-18-2004 12:10 AM


All times are GMT -5. The time now is 02:04 AM.

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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration