grep file to find unique instances of username


 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications grep file to find unique instances of username
# 1  
Old 01-13-2011
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...
# 2  
Old 01-13-2011
Code:
awk -F '/' ' /^Principal/ {arr[$NF]++; n} {next} END{ for (i in arr) {print i}}'  SystemOut.log

Try this.
This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 01-13-2011
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.
# 4  
Old 01-13-2011
Or:
Code:
awk -F '/' '{print $2}' SystemOut.log | sort | uniq > /tmp/uniq_users.txt

This User Gave Thanks to methyl For This Post:
# 5  
Old 01-14-2011
This works great. Thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using grep and a parameter file to return unique values

Hello Everyone! I have updated the first post so that my intentions are easier to understand, and also attached sample files (post #18). I have over 500 text files in a directory. Over 1 GB of data. The data in those files is organised in lines: My intention is to return one line per... (23 Replies)
Discussion started by: clippertm
23 Replies

2. UNIX for Dummies Questions & Answers

Grep to find matching patern and return unique values

Request: grep to find given matching patern and return unique values, eliminate the duplicate values I have to retrieve the unique folder on the below file contents like; /app/oracle/build_lib/pkg320.0_20120927 /app/oracle/build_lib/pkg320.0_20121004_prof... (5 Replies)
Discussion started by: Siva SQL
5 Replies

3. Shell Programming and Scripting

List unique values and count instances in .csv file

I need to take the second column of a .csv file and count the number of instances of each unique value in that same second column. I'd like the output to be value,count sorted by most instances. Thanks for any guidance! Data example: 317476,317756,0 816063,318861,0 313123,319091,0... (4 Replies)
Discussion started by: batcho
4 Replies

4. UNIX for Dummies Questions & Answers

Find all the unique file extensions

Hi How can i find the unique list of file extensions in a folder/subfolders e.g. MAIN/ a.txt b.txt a.clas a.java b.class a.txt.112 c.12.ram.jar i just need to get the below out irrespective of file being present in folder or subfolders txt clas java (5 Replies)
Discussion started by: reldb
5 Replies

5. Shell Programming and Scripting

Grep with multiple instances of same pattern

Hi, This is my text file I'm trying to Grep. Apple Location Greenland Rdsds dsds fdfd ddsads http Received Return Immediately Received End My Grep command: grep only--matching 'Location.*Received' Because the keyword Received appears twice, the Grep command will stop at the last... (3 Replies)
Discussion started by: spywarebox
3 Replies

6. Shell Programming and Scripting

Grep with multiple instances of same pattern

Hi, This is my text file I'm trying to Grep. Apple Location Greenland Rdsds dsds fdfd ddsads http Received Return Immediately Received End My Grep command: grep only--matching 'Location.*Received' e. Because the keyword Received appears twice, the Grep command will stop at the last... (0 Replies)
Discussion started by: spywarebox
0 Replies

7. Shell Programming and Scripting

Grep to find single instances of each ERROR type

i have a file that contents multiple instances of the same ERROR.Below the content of the file ERROR_FILE.txt Archiver6.log:2009-05-25 17:58:44,385 ERROR - CleanLPDataMessage: Missing Intervals: 2 Archiver6.log:2009-05-25 18:27:36,056 ERROR - CleanLPDataMessage: Missing Intervals: 5... (5 Replies)
Discussion started by: ali560045
5 Replies

8. Shell Programming and Scripting

To find the username in /etc/passwd file

Hi, I need to a shell script to list out only the username in the /etc/passwd file. Regards Siva (7 Replies)
Discussion started by: gsiva
7 Replies

9. Shell Programming and Scripting

How to replace all string instances found by find+grep

Hello all Im performing find + grep operation that looks like this : find . -name "*.dsp" | xargs grep -on Project.lib | grep -v ':0' and I like to add to this one liner the possibility to replace the string " Project.lib" that found ( more then once in file ) with "Example.lib" how can I do... (0 Replies)
Discussion started by: umen
0 Replies

10. UNIX for Dummies Questions & Answers

Find, make and move file based on username

hi there, i'm new to UNIX( just 3month used), i found my new box contained alot of files and directories in /home/box/ i've tried to search script in tis forum and found many of them but, i don't know how to combine them to make a script, although using pipes. my tasks are: 1) to scan user... (5 Replies)
Discussion started by: Helmi
5 Replies
Login or Register to Ask a Question