awk 试图 return 登录超过 4 分钟的用户的值
Awk trying to return value of users logged in for more than 4 minutes
我正在使用一个文件,其中用户登录的时间在 $10 字段中。我试图列出所有当前未登录且已登录超过 4 分钟的用户
我试过这个:
last | awk '(!"in"){if >00.04)print ,}' sort -nr | less
它没有返回任何信息,如果我将 returns 个 "logged in" 人排除在外($10!"in")。这是语法问题还是小时、分钟不能与大于号比较?
!"in"
不起作用是因为您要查找的运算符是 !=
(不等于)。但是,仅此还不够。当 </code> 的值类似于 <code>(12:34)
时, > 00.04
将不起作用;你必须把它分开。一个可能性是
last | awk ' != "in" { gsub(/\(\)/, "", ); split(, t, ":"); if(t[1] > 0 || t[2] > 4) print , }' | sort -nr | less
awk代码为
!= "in" { # in a line where is not "in"
gsub(/\(\)/, "", ) # remove parentheses from
split(, t, ":") # split at the : into t
if(t[1] > 0 || t[2] > 4) { # t[1] is the hours, t[2] the minutes, so this
# checks whether is more than 4 minutes
print , # and prints , ( without parentheses
# because we removed them). If that is not
# desired, make a copy of before paren
# removal and splitting.
}
}
顺便说一句,我没有检查last
的输出是否标准化。我怀疑它不是,所以这不太可能很便携。
last |awk '{if(>00.04 && !~ "in" ){print ,}}'|sort -nr | less
..
>00.04 && !~ "in" # if field 10 is greater than 00.04 and does not matches "in"
我正在使用一个文件,其中用户登录的时间在 $10 字段中。我试图列出所有当前未登录且已登录超过 4 分钟的用户 我试过这个:
last | awk '(!"in"){if >00.04)print ,}' sort -nr | less
它没有返回任何信息,如果我将 returns 个 "logged in" 人排除在外($10!"in")。这是语法问题还是小时、分钟不能与大于号比较?
!"in"
不起作用是因为您要查找的运算符是 !=
(不等于)。但是,仅此还不够。当 </code> 的值类似于 <code>(12:34)
时, > 00.04
将不起作用;你必须把它分开。一个可能性是
last | awk ' != "in" { gsub(/\(\)/, "", ); split(, t, ":"); if(t[1] > 0 || t[2] > 4) print , }' | sort -nr | less
awk代码为
!= "in" { # in a line where is not "in"
gsub(/\(\)/, "", ) # remove parentheses from
split(, t, ":") # split at the : into t
if(t[1] > 0 || t[2] > 4) { # t[1] is the hours, t[2] the minutes, so this
# checks whether is more than 4 minutes
print , # and prints , ( without parentheses
# because we removed them). If that is not
# desired, make a copy of before paren
# removal and splitting.
}
}
顺便说一句,我没有检查last
的输出是否标准化。我怀疑它不是,所以这不太可能很便携。
last |awk '{if(>00.04 && !~ "in" ){print ,}}'|sort -nr | less
..
>00.04 && !~ "in" # if field 10 is greater than 00.04 and does not matches "in"