[英]Convert slurm accounting output
I'm looking for a way to get the elapsed time output to always include days, at the moment I can't see away in defining an output format so I'm looking at using cut, awk, sed or similar command(s) to do this after the output has been generated. 我正在寻找一种方法来使经过的时间输出始终包括天数,目前还无法定义输出格式,因此我正在考虑使用cut,awk,sed或类似命令在生成输出后执行此操作。
So any ideas how I can change output such as: 因此,我有任何想法可以更改输出,例如:
JobID|Partition|User|State|Elapsed|
902464|interactive-a|bob|COMPLETED|10-00:10:40
968491|interactive-a|bob|COMPLETED|12:49:20
970801|interactive-a|sam|COMPLETED|07:00:46
912973|interactive-a|tom|COMPLETED|41-02:34:41
971356|interactive-a|mat|COMPLETED|04:36:35
971912|interactive-a|mat|COMPLETED|02:12:02
972668|interactive-a|mat|COMPLETED|00:09:06
Into this format (the last column has 0- added where needed) 转换成这种格式(最后一列在需要时添加了0-)
JobID|Partition|User|State|Elapsed|
902464|interactive-a|bob|COMPLETED|10-00:10:40|
968491|interactive-a|bob|COMPLETED|0-12:49:20|
970801|interactive-a|sam|COMPLETED|0-07:00:46|
912973|interactive-a|tom|COMPLETED|41-02:34:41|
971356|interactive-a|mat|COMPLETED|0-04:36:35|
971912|interactive-a|mat|COMPLETED|0-02:12:02|
972668|interactive-a|mat|COMPLETED|0-00:09:06|
Thanks 谢谢
$ sed 's/|\([0-9:]\{1,\}\)$/|0-\1/' file
JobID|Partition|User|State|Elapsed|
902464|interactive-a|bob|COMPLETED|10-00:10:40
968491|interactive-a|bob|COMPLETED|0-12:49:20
970801|interactive-a|sam|COMPLETED|0-07:00:46
912973|interactive-a|tom|COMPLETED|41-02:34:41
971356|interactive-a|mat|COMPLETED|0-04:36:35
971912|interactive-a|mat|COMPLETED|0-02:12:02
972668|interactive-a|mat|COMPLETED|0-00:09:06
In awk: 在awk中:
$ awk -F\| '$5 ~ /-|E/ || ($5 = "0-" $5) && gsub(/ /,"|")' file
-F\\|
set FS
to |
FS
设置为|
$5 ~ /-|E/
matches and prints records with -
OR E
in fifth field $5 ~ /-|E/
比赛和与打印记录-
OR E
在五分场 ||
logical OR, ie. ($5 = "0-" $5)
prepend 0-
to fifth field ($5 = "0-" $5)
在第5个字段前加0-
&& gsub(/ /,"|")
AND replace those space-replaced field separators with |
&& gsub(/ /,"|")
和替换用的那些空间置换字段分隔符|
s. above could be removed if -v OFS="|"
如果
-v OFS="|"
则可以删除上面的内容 was used: 使用:
$ awk -v OFS=\\| $ awk -v OFS = \\ | -F\\|
-F \\ | '$5 ~ /-|E/ ||
'$ 5〜/-| E / || ($5 = "0-" $5)' file
($ 5 =“ 0-” $ 5)'文件
$ awk -v OFS=\\| $ awk -v OFS = \\ | -F\\|
-F \\ | '$5 ~ /-|E/ ||
'$ 5〜/-| E / || ($5 = "0-" $5)' file
($ 5 =“ 0-” $ 5)'文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.