grep file to find unique instances of username

hello -

A SystemOut.log file has recurring entries that follow this format:

Principal: auth9.nick.al.gov:389/USERNAME

Over the course of a day thousands of lines similar to this are produced, with each username represented hundreds of times.

I need to create a new file that shows each user that accessed the system during the day. I just need a list that show all the names that logged in at least once. The number of times a user accesses the system is not important.

I know I need to grep for "Principal" but I'm not sure how to capture unique usernames at only one time.

thanks for any help...

awk -F '/' ' /^Principal/ {arr[$NF]++; n} {next} END{ for (i in arr) {print i}}'  SystemOut.log

Try this.

1 Like

Hmmm.. this took awhile but didn't return any results.

Hoping to get output that reads:

JOE
BOB
MARY

Thanks...

---------- Post updated at 02:31 PM ---------- Previous update was at 02:21 PM ----------

removed a "^" and so that it reads:

awk -F '/' ' /Principal/ {arr[$NF]++; n} {next} END{ for (i in arr) {print i}}' SystemOut.log > userlist.txt

now works great. thank you!

---------- Post updated at 02:52 PM ---------- Previous update was at 02:31 PM ----------

Seems to work on linux but not AIX. Must be a difference in the awk version.

Or:

awk -F '/' '{print $2}' SystemOut.log | sort | uniq > /tmp/uniq_users.txt
1 Like

This works great. Thank you!