in reply to Redone DB split help needed
This code snippet will hopefully help you. It reads lines and stores them into an array until the token 'TIMESTEP' is found. Afterwards, the array is iterated and each element is written to the appropriate file. Since you did not supply a data file, i will with the help of our friends from 'Mr. Show'. Here they are, doing Shakespeare:
output.txt:I'm the king! I'm mad! I want the news from my kingdom! TIMESTEP I'm the queen! Blah blah blah! Look at me! TIMESTEP Your majesty, I'm a clown or something.. I've got makeup on my face, 'cause my mommy and daddy didn't give me enough attention! TIMESTEP I'm a big actor! Look at the great big actor on the stage! I yell the loudest! Look at me! TIMESTEP Oh mighty king! We are your sons! We're loud, stupid actors and we're gonna have a big dumb sword fight, in your honor! TIMESTEPAnd here is the script:
After you execute this script, you will have 5 files: BRO01.pdb, BRO02.pdb, BRO03.pdb, BRO04.pdb, and BRO05.pdb. Read up on sprintf for more info about that highly useful function.use strict; my @superchunk; # i think i'm hyper enough as it is ... my $i = 0; open(IN,'output.txt') or die $!; # process one line at a time # add each line to the element that $i is # increment $i when TIMESTEP is encountered while (<IN>) { $superchunk[$i] .= $_; $i++ if /^TIMESTEP/; } close IN; $i = 1; # process one element at a time # use sprintf to create the name of the file # write that element to the file for (@superchunk) { my $file = sprintf("%s%02d%s",'BRO',$i++,'.pdb'); open(OUT,">$file") or die "can't write to $file: $!"; print OUT $_; }
Final thought, instead of storing the lines to be written in an array, consider writing them out inside the while loop instead. This works better for very large files, but if you have plenty of RAM then storing them in an array first should be OK.
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|