ubuntu awk 取last 帐号跟时间问题

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

last资料长相如下。

我想取得的资料像图片。

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


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

回答

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

以上是 ubuntu awk 取last 帐号跟时间问题 的全部内容, 来源链接: utcz.com/a/43543.html

回到顶部