last command in linux shows the last logins in the system.
Is there any script that I can retrive only the date of the these last logins?
thanks
CodePudding user response:
Quick n dirty
$ last | grep -v "system boot" | awk '{for (i=4; i<NF; i ) printf $i " "; print $NF}'
CodePudding user response:
last | {m,g}awk 'gsub(/\t/, " ", $!(NF *= /system boot/))^_ * NF' \
FS='^[ \t]*[^ \t]*[ \t] [^ \t]*[ \t] [^ \t]*[ \t] ' OFS=
I only have macos ~ (BSD 4.4)
and not Linux
here so I can't test the output of it (even the last
command looks different here). Let me know if this works or not.
If you don't care for that final gsub()
bit that's more nice to have than essential, then the body is even simpler :
{m,g}awk 'NF *= /system boot/' { FS=... OFS=... }