Mercurial > hg > cc > cirrus_work
annotate bin/share_by_task.sh @ 221:3d752f01e6fb
minor addition?
author | Henry Thompson <ht@markup.co.uk> |
---|---|
date | Wed, 28 Feb 2024 10:32:01 +0000 |
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 |