Mercurial > hg > cc > cirrus_work
annotate bin/share_by_task.sh @ 101:e2e64c3d763e
bug4 fixed, but that created a new, earlier bug
| author | Henry S. Thompson <ht@inf.ed.ac.uk> |
|---|---|
| date | Mon, 11 Sep 2023 22:06:45 +0100 |
| parents | dfdb95e5d774 |
| children |
| rev | line source |
|---|---|
| 11 | 1 #!/bin/bash |
| 2 # Usage: share_by_task.sh [-f format] [-s from to] N task | |
| 3 # Filter a sequence by mod N == task | |
| 4 # Sequence is stdin, or if -s then seq $from $t | |
| 5 if [ "$1" = '-f' ] | |
| 6 then | |
| 7 shift | |
| 8 f=$1 | |
| 9 shift | |
| 10 else | |
| 11 f='%s\n' | |
| 12 fi | |
| 13 | |
| 14 if [ "$1" = '-s' ] | |
| 15 then | |
| 16 shift | |
| 17 source="seq $1 $2" | |
| 18 shift | |
| 19 shift | |
| 20 else | |
| 21 source="cat" | |
| 22 fi | |
| 23 | |
| 24 pos=0 | |
| 25 ${source} | while read v | |
| 26 do | |
| 27 if [ $((++pos % $1)) -eq $2 ] | |
| 28 then | |
| 29 printf "$f" $v | |
| 30 fi | |
| 31 done |
