-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconcurrency.sh
executable file
·46 lines (41 loc) · 1013 Bytes
/
concurrency.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bash
usage(){
cat << EOF
usage: $(basename $0) -f 1,2 OPTIONS INFILE COMMAND
opthins:
-f STR Fields to partition the input into the jobs
-c INT The concurrency jobs number[5]
-h Show this message
EOF
}
if [ "X$1" == "X" ];then
usage
exit
fi
SEP=@
CONC=5
while getopts "hf:s:c:" OPTION
do
case $OPTION in
h) usage; exit 1;;
f) FIELDS=$OPTARG;;
s) SEP=$OPTARG;;
c) CONC=$OPTARG;;
?) usage; exit;;
esac
done
shift $((OPTIND - 1))
i=1
`mkdir -p concurrency`
for values in $(cut -f $FIELDS $1 | tr "\t" $SEP | sort -u);do
select.pl -f $FIELDS -s $SEP -v $values $1 >concurrency/prefix.$values.input
done
ls -Sr concurrency/prefix.*.tsv | while read file;do
baseName=$(basename $file .input)
if [ $(($i%$CONC)) -eq 0 ];then
$2 $file >concurrency/$baseName.out 2>concurrency/$baseName.err
else
$2 $file >concurrency/$basename.out 2>concurrency/$baseName.err &
fi
i=$(($i+1))
done