shragi
asked on
java split csv file into multiple csv files
Hi
I have a csv file with 4003 lines and the file name is "testnow.csv"
I want to split this csv file into 41 csv files, I mean each csv file cannot have more than 100 lines
and the new csv file name should be somthing like this
testnow_1.csv
testnow_2.csv
testnow_3.csv
.....
testnow_41.csv
Thanks,
I have a csv file with 4003 lines and the file name is "testnow.csv"
I want to split this csv file into 41 csv files, I mean each csv file cannot have more than 100 lines
and the new csv file name should be somthing like this
testnow_1.csv
testnow_2.csv
testnow_3.csv
.....
testnow_41.csv
Thanks,
What's your OS?
ASKER
Windows
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@FishMOnger
small problem with your script, in order to use your script the files should be readily created before hand.
But is it possible to create the file along with the other logic.
Thanks
small problem with your script, in order to use your script the files should be readily created before hand.
But is it possible to create the file along with the other logic.
Thanks
You said you have a csv file with 4003 lines
But if you need to create it, that can be done if you have the logic to generate the contents.
But if you need to create it, that can be done if you have the logic to generate the contents.
>>in order to use your script the files should be readily created before hand.
That's not the case. Did you try it?
That's not the case. Did you try it?
@CEHJ
The code I gave does require the input csv file to already exist but not the output file.
I just noticed that I have a typo in the code which will cause it to fail. I opened the output file in read mode, which certainly is not what is wanted.
Change:
To:
The code I gave does require the input csv file to already exist but not the output file.
I just noticed that I have a typo in the code which will cause it to fail. I opened the output file in read mode, which certainly is not what is wanted.
Change:
open(my $csv_out, '<', "testnow_$num.csv")
To:
open(my $csv_out, '>', "testnow_$num.csv")