If I run this on OS X:
last -10 | awk '{print $1}'
I get:
chop
chop
chop
chrihopk
reboot
shutdown
chop
chop
chop
chrihopk
How do I use sed or awk to obtain the most frequent user 'chop'?
ADDITIONAL EDIT TO QUESTION:
Our local admin account interferes with the results (username: support) and often we have a new starter on a client box.
How could I modify
last -1
to omit the following and return the last valid username:
support
reboot
shutdown
Thanks
bash$ last -10 | awk '{print $1}' | sort | uniq -c | sort -nr | head -1 | awk '{print $2}'
sort -un
does something, but I'm not sure what...
bash$ echo -e 'bob\nbob\ncat\ncat\ncat\ndog'
bob
bob
cat
cat
cat
dog
bash$ echo -e 'bob\nbob\ncat\ncat\ncat\ndog' | sort | uniq -c | sort -nr
3 cat
2 bob
1 dog
bash$ echo -e 'bob\nbob\ncat\ncat\ncat\ndog' | sort -un
bob
bash$ echo -e 'bob\nbob\ncat\ncat\ncat\ndog' | sort | uniq -c | sort -nr | head -n1 | awk '{print $2}'
cat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With