![]() |
![]() |
#1 | |
Dec 2011
After milion nines:)
162310 Posts |
![]()
I need script that will "ask" me number of workers and then split input file equally into worktodo.txt file ( and if possible add "Worker line") ( in this case 3 workers)
Quote:
Thanks |
|
![]() |
![]() |
![]() |
#2 |
Sep 2002
Database er0rr
23·3·11·17 Posts |
![]() |
![]() |
![]() |
![]() |
#3 |
"Oliver"
Sep 2017
Porta Westfalica, DE
1,321 Posts |
![]()
In bash:
Code:
if [ $# -ne 3 ]; then echo 'Usage: bash splitter.sh [in file] [out file] [number of workers]'; exit -1; fi; if ls "$1."* 1> /dev/null 2>&1; then echo 'Temporary files could not be created.'; exit -2; fi; range=$(seq 1 $3); if [ $? -ne 0 ]; then echo 'The worker count was not numerical.'; exit -3; fi; for w in $range; do echo "[Worker #$w]" >> "$1.tmp"; done; cat "$1" >> "$1.tmp"; split -n r/$3 "$1.tmp" "$1.s"; cat "$1.s"* > "$2"; rm "$1."*; |
![]() |
![]() |
![]() |
#4 |
Dec 2011
After milion nines:)
3·541 Posts |
![]() |
![]() |
![]() |
![]() |
#5 |
6809 > 6502
"""""""""""""""""""
Aug 2003
101ร103 Posts
252148 Posts |
![]()
What about this tool? https://www.mersenne.ca/balance.php
|
![]() |
![]() |
![]() |
#6 | |
Dec 2011
After milion nines:)
3×541 Posts |
![]() Quote:
|
|
![]() |
![]() |
![]() |
#7 | |
Dec 2011
After milion nines:)
65716 Posts |
![]() Quote:
|
|
![]() |
![]() |
![]() |
#8 | |
Dec 2011
After milion nines:)
3·541 Posts |
![]() Quote:
Work perfect. Now I will see can I adopt it to Win Thanks! |
|
![]() |
![]() |
![]() |
#9 |
6809 > 6502
"""""""""""""""""""
Aug 2003
101ร103 Posts
22×7×389 Posts |
![]()
I just tried it with some made up PRP lines and it recognized them, sorted them, and attempted to balance them.
|
![]() |
![]() |
![]() |
#10 |
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2
89·113 Posts |
![]()
bash
Code:
N=3 for i in `seq 1 $N`; do echo '[Worker #'$i']'; awk 'a++%'$N'=='$i'-1' input.txt done > output.txt |
![]() |
![]() |
![]() |
#11 |
Sep 2002
Database er0rr
23·3·11·17 Posts |
![]()
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 |
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
BASH script segment won't work in larger script | EdH | Programming | 41 | 2021-10-15 22:07 |
CADO-NFS vs GGNFS and other NFS considerations [split from New Factoring Algorithm] | Dubslow | Factoring | 6 | 2018-04-27 19:56 |
split a prime95 queue & client installation | joblack | Information & Answers | 1 | 2009-01-06 08:45 |
Formula split up | JHansen | Homework Help | 4 | 2007-11-20 15:02 |
New theorem to split LL tests(Published) | nuggetprime | Miscellaneous Math | 9 | 2007-05-23 13:47 |