Randomise splitting file into two new files

B

Bumble

Hey all! Basically I require a program that will take a file full records (1
per line) and then output these lines into 2 new files, randomly. Anyone
know of such a program already in existence?

--
Bumble

"I'm flat out, you're so beautiful to look at when you cry. Freeze don't
move, you've been chosen as an extra in the movie adaptation of the sequel
to your life. Shady Lane, everyone wants one, Shady Lane, everybody needs
one" - Pavement
 
C

ctcgag

Bumble said:
Hey all! Basically I require a program that will take a file full records
(1 per line) and then output these lines into 2 new files, randomly.
Anyone know of such a program already in existence?

open F1, ">", pop or die $!;
open F2, ">", pop or die $!;
while (<>) {
if (rand()<0.5) {
print F1 $_;
} else {
print F2 $_;
};
};
close F1 or die $!;
close F2 or die $!;

Xho
 
B

Bumble

open F1, ">", pop or die $!;
open F2, ">", pop or die $!;
while (<>) {
if (rand()<0.5) {
print F1 $_;
} else {
print F2 $_;
};
};
close F1 or die $!;
close F2 or die $!;

Xho

Many thanks! Didn't realise it was so straight forward!! It's working great.

--
Bumble
http://bumble.rumble.at
http://www.cossar.co.uk

"I'm flat out, you're so beautiful to look at when you cry. Freeze
don't move, you've been chosen as an extra in the movie adaptation of
the sequel to your life. Shady Lane, everyone wants one, Shady Lane,
everybody needs one" - Pavement
 
J

John W. Krahn

Bumble said:
Hey all! Basically I require a program that will take a file full records (1
per line) and then output these lines into 2 new files, randomly. Anyone
know of such a program already in existence?

my @fh;
open $fh[ $_ ], '>', "test44_$_.txt" or die $! for 0, 1;
print { $fh[ rand @fh ] } $_ while <>;



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top