view bin/share_by_task.sh @ 243:7bef91ca3d51

make into a library, entry point def unpackz(infileName, callback, outfile = None), moved to python/lib/cc
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Wed, 02 Oct 2024 19:54:45 +0100
parents dfdb95e5d774
children
line wrap: on
line source

#!/bin/bash
# Usage: share_by_task.sh [-f format] [-s from to] N task
# Filter a sequence by mod N == task
# Sequence is stdin, or if -s then seq $from $t
if [ "$1" = '-f' ]
then
 shift
 f=$1
 shift
else
 f='%s\n'
fi

if [ "$1" = '-s' ]
then
 shift
 source="seq $1 $2"
 shift
 shift
else
 source="cat"
fi

pos=0
${source} | while read v
 do
  if [ $((++pos % $1)) -eq $2 ]
  then
    printf "$f" $v
  fi
 done