To split a big CSV file into mutiple csv's

Hi,

I have a CSV file containing 250000 records in it . I want to split the csv file into multiple files each of 25000 records .
Is it possible ?
if you suggest me code then do paste the code !

Thanks,
Shabaz

Hi
–yah thats possible
–use READ CSV FILE activity and pass the filepath as input and get the output with a variable of type datatable named dt

–followed by that use a while loop activity with a condition like this
counter > dt.Rows.Count
where counter is a variable of type int32 with default value as 25000 defined in the variable panel
–inside the loop use a assign activity like this
dt1 = dt.AsEnumerable().Skip(dt.Rows.Count-counter).CopyToDatatable()
where dt1 is a variable of type system.data.datatable with default value as New System.Data.Datatable

–now use a WRITE CSV FILE activity and mention the input as dt1 and mention the file path as
"yourfolderpath\yourfilename"+Now.ToString(“hh_mm_ss”)+".csv"

–then use CLEAR DATATABLE activity where mention the input as dt1
–and inside the while loop atlast use a assign activity like this
counter = counter + 25000

hope this would help you
kindly try this and let know for any queries or clarification
Cheers @SyedShabaz03

1 Like

Hi,

You can get it using Matches activity as the following steps.

First, read your whole csv fils as String type variable (strCsvData) using Read Text Activity.
Then, use Matches activity with the following settings.

  • Input : strCsvData
  • Pattern : "((.*?\n){25000}|((.*?\n?)){1,25000}$)"
  • Result : result (IEnunmerable<match> type variable)

Finally you use For Each Activity and set result in Value property, and use Write Text Activity in the loop

If you need header in each file, it requires to append the result string to header text before Write Text activity in the For Each loop.

Regards,

Hi @SyedShabaz03,

Here is the package that it has many to activity to facilitate the Text format file.

Here is the steps in picture

image

Sample : EasyText.zip (19.1 KB)

Regards
Balamurugan.S

1 Like

I’m having the csv file containing 84,536 rows.
My requirement is to split the 64,536 rows into new CSV file.
First split file can contain 64,536 and second file can contain the remaining rows.

Similarly if the count is more, it can be splitted to more csv files.

Could you please help to achieve this scenario.

1 Like

Hi @hari2010haran,

Welcome to UiPath Community !!

In above you can able to under well to split the file using the Read Specific line activity.

Regards
Balamurugan.S