perl - 如何在 Slurm 脚本中编写主机文件
问题描述
目前我正在关注
#!/bin/bash -l
#SBATCH --nodes=2
#SBATCH --ntasks-per-node=4
scontrol show hostname $SLURM_JOB_NODELIST | perl -ne 'chomb; print "$_" x4' > myhostfile
这会生成以下 myhostfile
compute-0
compute-0
compute-0
compute-0
compute-1
compute-1
compute-1
compute-1
我想得到以下结果
compute-0
compute-1
compute-0
compute-1
compute-0
compute-1
compute-0
compute-1
这样我们在所有指定节点之间交替
解决方案
你可以这样做:
$ perl -e 'print +(<>) x 4'
这会从您的代码中删除-n
循环,而是一次性读取整个循环STDIN
。我们需要括号()
将读取操作符放入列表上下文中,因此它会一次读取所有行。告诉 perl 解释器+
括号是一个列表,而不是print
(as print()
) 的一部分。最后x
,列表上下文中的重复运算符重复整个列表。
$ cat foo
0
1
$ cat foo | perl -e 'print +(<>) x 4'
0
1
0
1
0
1
0
1
推荐阅读
- python - 在 Mac 上运行 Tkinter
- amazon-s3 - Sentry 不会将 DSYM 文件上传到 S3 文件存储后端并给我异常:NoSuchKey: An error occurred (NoSuchKey)
- swift - 如何在 iOS 13 上以编程方式更改顶部栏背景 swift 4
- jmeter - 如何发送 RFH2 格式的消息?
- python - Python:如何检查日期是否不明确?
- javascript - 如果命令失败,则终止应用程序 Linux(Nodejs)
- c# - nservicebus 使用 msmq 传输发送具有列表类型属性的命令对象
- wordpress - 在自定义评论框中提交评论后如何弹出框?
- android - Android Studio 和 Android SDK 25 glob()
- winapi - 确定可移动磁盘的驱动器号(dos 名称)