Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
295 views
in Technique[技术] by (71.8m points)

ubuntu awk 取last 帐号跟时间问题

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

last资料长相如下。
xxx

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

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


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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

目前看到最优雅的解决方案 : 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...