问题描述
对于任何连续的整数范围, n1..n2
我如何使用命令行工具将其解析为长度为< = n
的范围?
For any sequential range of integers, n1..n2
how can I use command line tools to parse them into ranges of length <= n
?
作为一个具体示例,我有一个目录,其中包含名为 1253..2050
的文件夹.每个文件夹都有一个名为 job.sh
的脚本,我可以分批提交20个作业(因为每个节点有20个核心).因此,我想生成以下命令:
As a specific example, I have a directory with folders named 1253..2050
. Each folder has a script called job.sh
, and I can submit them in batches of 20 jobs (since each node has 20 cores). Thus, I want to generate the following commands:
echo {1253..1301}
在特定情况下,我可以使用/bin/ls
或 cat runtime.txt
生成此整数序列.
For a particular case I can generate this sequence of integers using either /bin/ls
or cat runs.txt
.
qsub -t 1253-1272 array.pbs
qsub -t 1273-1292 array.pbs
qsub -t 1293-1301 array.pbs
推荐答案
这应该做您想要的.
count=20
off=0
dirs=(*)
while (( (off + count) < ${#dirs[@]} )); do
qsub -t ${dirs[off]}-${dirs[off+count]} array.pbs
((off+=count + 1))
done
if [ $off -ne ${#dirs[@]} ]; then
qsub -t ${dirs[off]}-${dirs[@]: -1} array.pbs
fi
在您的情况下,最后一个 if
可能不是必需的,并且此循环排序过程假设范围将是完整的(我假设 qsub
期望也).
That last if
is probably not necessary in your case and this loop sort-of assumes that the ranges are going to be complete (I'm assuming qsub
expects that too).
这篇关于在命令行将数字序列解析为20的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!