Split text file full of emails, 10,000 at a time, into new text files

Hi

I have a .txt file with a lot! of emails. I need to split this .txt files into multiple .txt files each with 10,000 emails.

The original .txt is just email addresses each on a new line.

Thanks

Mark

1 Like

Hi Mark,

Can you share a sample text file so as to give the split expression better.

1 Like

Results_Valid.zip (689 Bytes)

Here is a sample .txt file. (I have changed the emails so they are not real)

So, I want to take these emails and save them in new .txt files with 10 emails in each .txt file.

Thanks

Mark

1 Like

Hi Mark,

I’m attaching the workflow which extracts 10 emails and places in a text file. In the same way you can increase the counter (ie n in my script) to 10 for the next 10 emails
.Main.xaml (8.2 KB)

2 Likes

@Rahul_Pasupuleti

Thanks. Will this not just append all the emails back into one .txt file?

1 Like

I try this with my data and i just get one .txt file with 10 emails in.

1 Like

Hi Mark,

Here is the updated code which generates txt files which contain 10 emails.

Main.xaml (10.2 KB)

Please run it and get back if you face any issues

1 Like

Awesome. Thank you @Rahul_Pasupuleti

1 Like

Hi @MarkC1500 @Rahul_Pasupuleti
There’s only one problem with this is that,
it is not getting 12th, 22nd, 32… line (text) from the main text file, I mean there’s line no “1-11”, “13-21” , “23-31” present in newly created 1st, 2nd and 3rd text files respectively . (excluding line no 12 and 22)

It’s because of two things.

  1. if condition has “n<=k” expression.
  2. n=n+1 is out of the “If” condition, as shown below :

So firstly, n<=k means untill n becomes 10 BUT Spliting(10) is nothing but 11th line((10) is the index of array). because of this it takes 1-11 line for the 1st text file,
Secondly, n=n+1 increments n value even after else part.
e.g. When n became 12 and it check for If condition, because of it doesn’t satisfied with the condition, the flow goes into else part, In Else there’s “k=k+10” so k became 20, after that there’s n=n+1 so n incremented and became 13,
Like this 12 (value of n) skipped.

So I think there’re 3 required changes.

  1. If condition should have n<k expression.
  2. n=n+1 should be there in Then part and next to “Append” activity.
  3. Don’t forget to copy paste the Then part sequence into else (Next to the “k=k+10”)

Like this:

check it by putting only 1 to 30 or 35 numbers line by line in main text file, it’ll be easy for understanding,
Check it and let me know.

Thanks & Regards,
Samir.

3 Likes

Thanks @samir

You were right and now sorted.

Mark

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.