Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Breaking One text file into four text file

Status
Not open for further replies.

lavadan

Programmer
Dec 17, 2007
49
US
Hi,

I am new to VB script. Hope someone can help(give me a clue) me with this task.


I have a text file with 100 member id like

12300012
23400015
.
.
.
45600078

I want to break this text file 4 text file such that each text file contains 25 member id. Can anyone suggest me a logic to do this?
 
There are several ways to go about this, but essentially they all revolve around reading the big file and writing 1/4th of the entries to each of 4 smaller files. What have you tried so far?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Hi,

I am new to VB script. Hope someone can help(give me a clue) me with this task.


I have a text file(member.txt) with 100 member id like

12300012
23400015
.
.
.
45600078

I want to break this text file into 4(member1.txt,member2.txt,member3.txt,member4.txt) text files such that each text file contains 25 member id. Can anyone suggest me a logic to do this?
 
Does the order matter? So do the first 25 have to go into one file, then the next 25 in the next file, etc. Or would it be ok if member1.txt held every fourth id?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I really dont know the logic how to do this.I am thinking of something like this:

Initialize a counter to zero
Read a line in the text file
write it to a new text(member1.txt) file
Repeat read and write Until counter reaches 25

After this set the counter to zer0
read and write into text file 2(member2.txt)
Reset counter to zero after it reaches to 25

I dont know whether there is any simple logic than this?

 
Order is not really important but the id in one text file should not be repeated in another text file . Like member id 2300123 should not be present in member1.txt and member2.txt. It should be present in only one text file.
 
In that case I would do it this way:

Initialize a counter to 0
Open the big file
For Each line in the big file:
Select Case counter MOD 4
Case 0
Write the line to file 1
Case 1
Write the line to file 2
Case 2
Write the line to file 3
Case 3
Write the line to file 4
End Select
Increment the counter
Next



The advantage to this logic is that it won't matter if the size of the big file changes over time, you will always get 4 roughly equal files.


[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top