View Single Post
Old 2022-05-11, 00:37   #11
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

72·89 Posts
Default

Here is a perl script. usage: perl myscript.pl input_file worker_count > output_file

Code:
open(fh,"<",$ARGV[0]);
$count=0;
while(<fh>){$count++;}
close(fh);

open(fh,"<",$ARGV[0]);
$per_worker=int($count/$ARGV[1]);
$extras=$count%$ARGV[1];
$worker_blurb="[Worker \#";
$worker=0;
while(<fh>){
        $line=$_;
        $count++;
        if($count>$per_worker){
                $count=0;
                print("\n");
                $worker++;
                print($worker_blurb.$worker."]\n");
                if($extras==0){$per_worker--;}
                $extras--;
        }
        print($line);
}
close(fh);

Last fiddled with by paulunderwood on 2022-05-11 at 01:18
paulunderwood is offline   Reply With Quote