EDIT1: 要使用ps 命令运行它,请使用:
ps -ef | awk '
{
split($7,array,":")
tot_time=array[2]*60+array[3]
if(tot_time>60){
print $2,$7,$8
}
tot_time=""
delete array
}
'
还涵盖 1 个边缘情况,即进程运行时间准确为 1 小时且小于 1 分钟 :) 尝试以下操作。
ps -ef | awk '
{
split($7,array,":")
tot_time=array[1]*3600+array[2]*60+array[3]
if(tot_time>60){
print $2,$7,$8
}
tot_time=""
delete array
}
'
请您尝试以下操作。将第 7 列拆分为 3 个不同的部分(小时、分钟和秒),分隔符为 :,然后从中计算分钟以检查其值是否大于 60。
awk '
{
split($7,array,":")
tot_time=array[2]*60+array[3]
if(tot_time>60){
print $2,$7,$8
}
tot_time=""
delete array
}
' Input_file
用样本测试:
cat Input_file
Field1 Field2 Field3 Field4 Field5 Field6 Field7 Field8
xxx xxx xxx xxx xxx xxx 00:01:01 xxx
xxx xxx xxx xxx xxx xxx 00:00:48 xxx
运行后的代码将是输出。
awk '
{
split($7,array,":")
tot_time=array[2]*60+array[3]
if(tot_time>60){
print $2,$7,$8
}
tot_time=""
delete array
}
' Input_file
xxx 00:01:01 xxx