ubuntu awk 取last 帐号跟时间问题

这边尝试学习,发现想要ubuntu awk 取last 账号跟时间会遇到以下问题。

last资料长相如下。
xxx

我想取得的资料像图片。
xxx

但实际我下以下命令 : last | awk '{print $1"\t"$4}'
xxx
xxx


更新
观察1 : 我这边观察到 awk $N 是以空白来做切分的原因导致。

阅读 1.5k
2 个回答

目前看到最优雅的解决方案 : last | awk -v FIELDWIDTHS='9 30 16' '{print $1 $3}'

test@test:~$ last | awk -v FIELDWIDTHS='9 30 16' '{print $1 $3}'
test     Tue Sep 15 14:39
test     Mon Sep 14 08:38
test     Mon Sep 14 03:32
test     Mon Sep 14 03:31
test     Mon Sep 14 03:22
test     Mon Sep 14 03:00
test     Mon Sep 14 02:11
test     Sun Sep 13 11:34
test     Sun Sep 13 11:33
test     Sun Sep 13 10:53
reboot   Sun Sep 13 10:53
test     Wed Sep  9 08:39
test     Wed Sep  9 07:04
reboot   Wed Sep  9 03:06
reboot   Wed Sep  9 03:04
test     Wed Sep  9 03:03
reboot   Wed Sep  9 03:03
test     Wed Sep  9 03:02
test     Wed Sep  9 02:51
reboot   Wed Sep  9 02:50

last | awk -v INGORECASE=0 '{ match($0,/([a-z]+?).*?([WTMFS][a-z][a-z] [A-Z].*?)-/,a);print a[1]"\t"a[2]}'

试试这个看下.

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题