Awk正在尝试返回登录时间超过4分钟的用户的值

Awk正在尝试返回登录时间超过4分钟的用户的值,awk,Awk,我使用的文件中,用户登录的时间在$10字段中。我正在尝试列出当前未登录且已登录超过4分钟的所有用户 我试过这个: last | awk '($10!"in"){if $10>00.04)print $10,$1}' sort -nr | less 它不返回任何信息,如果我删除($10!)它将返回“登录”的用户。这是语法问题还是小时、分钟与大于号不可比?那$10!“in”不起作用是因为您要找的操作员是=(不等于)。不过,光靠这一点还不够$10>00.04将不起作用;你得把它分开。一种可能性

我使用的文件中,用户登录的时间在$10字段中。我正在尝试列出当前未登录且已登录超过4分钟的所有用户 我试过这个:

last | awk '($10!"in"){if $10>00.04)print $10,$1}' sort -nr | less
它不返回任何信息,如果我删除($10!)它将返回“登录”的用户。这是语法问题还是小时、分钟与大于号不可比?

$10!“in”
不起作用是因为您要找的操作员是
=(不等于)。不过,光靠这一点还不够<当
$10
具有类似
(12:34)
的值时,code>$10>00.04
将不起作用;你得把它分开。一种可能性是

last | awk '$10 != "in" { gsub(/\(\)/, "", $10); split($10, t, ":"); if(t[1] > 0 || t[2] > 4) print $10, $1 }' | sort -nr  | less
awk代码是

$10 != "in" {                 # in a line where $10 is not "in"
  gsub(/\(\)/, "", $10)       # remove parentheses from $10
  split($10, t, ":")          # split $10 at the : into t
  if(t[1] > 0 || t[2] > 4) {  # t[1] is the hours, t[2] the minutes, so this
                              # checks whether $10 is more than 4 minutes
    print $10, $1             # and prints $10, $1 ($10 without parentheses
                              # because we removed them). If that is not
                              # desired, make a copy of $10 before paren
                              # removal and splitting.
  }
}
顺便说一下,我还没有检查
last
的输出是否标准化。我怀疑它不是,因此这不太可能是非常便携的

last |awk '{if($10>00.04 && $10 !~ "in" ){print $10,$1}}'|sort -nr | less


用你自己的话来说,你想用
($10!“)
做什么?我试图消除字段中出现文本“in”的行,这样我就可以比较大于4分钟的值。awk倾向于搜索数字匹配字段,即使该字段包含数字和字母的混合。
$10>00.04 && $10 !~ "in" # if field 10 is greater than 00.04 and does not matches "in"