Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
05-01-2006, 10:54 AM
|
#1
|
Member
Registered: Mar 2005
Location: Central Ohio, USA
Distribution: Fedora 7 x86_64 (home server), IPCop (home gateway), CentOS (work laptop), lots more at work.
Posts: 32
Rep:
|
Removing non-unique record in nawk
Hi all,
We have our Windows clients configured to report to a UNIX syslog server. We want to parse that log file using nawk to keep a list of who is logged on. The list is going to be in a plain-text file. What I need to be able to do is remove only one entry from the file that is not unique using nawk and any system commands or utilities available. Example input from the file:
Code:
Apr-28-machine-logon-jsmith
Apr-28-machine-logon-jsmith
Apr-28-machine-logon-jsmith
The script then sees this line in the log file it parses:
Code:
Apr-28-machine-logoff-jsmith
and we want it to remove only one instance of the corresponding logon entry, leaving the other 2, so that when
Code:
Apr-28-machine-logoff-jsmith
Apr-28-machine-logoff-jsmith
shows up in the log file it parses, it will remove the other 2.
Basically, we want the script to only remove one instance of the "logon" entry for each logoff entry. I've looked at sort, uniq, nawk, and a few other methods, without ideas. What does that community have to say?
Thanks everyone!
Last edited by omega71122; 04-30-2007 at 02:56 PM.
|
|
|
05-01-2006, 05:46 PM
|
#2
|
Senior Member
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524
Rep:
|
Okay, so exactly what is the spec? Let me see if I got it straight: For each line in the input file, if it hasn't been output before, output it.
If that's the effect you want, the following python script does it:
Code:
#!/usr/bin/python
try: set
except NameError: from sets import Set as set
from sys import stdin, stdout
lines = set()
for line in stdin:
if line not in lines:
lines.add(line)
print line,
save it as script.py, then run it as "python script.py < inputfile". Or change the hash-bang path and chmod +x it, and run it as "/path/script.py < inputfile". It should work with both python 2.3 and 2.4
hth --Jonas
|
|
|
05-02-2006, 09:38 AM
|
#3
|
Member
Registered: Mar 2005
Location: Central Ohio, USA
Distribution: Fedora 7 x86_64 (home server), IPCop (home gateway), CentOS (work laptop), lots more at work.
Posts: 32
Original Poster
Rep:
|
Basically we want the the file the script creates (/var/log/currentusers) to contain only logon entries. When the script sees a logoff entry in the syslog file (in this case /var/log/windowslog/current), we want it to remove an instance of the corresponding logon in the currentusers file. In the end, we want to be able to look at the currentusers file to quickly tell who's logged on.
I wish there was a way I could call nawk recursively...
|
|
|
05-02-2006, 09:43 AM
|
#4
|
Senior Member
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524
Rep:
|
Ah. I misunderstood that, then.
Have a look at who, w, utmp and wtmp. Will they do the job?
|
|
|
05-03-2006, 10:45 AM
|
#5
|
Member
Registered: Mar 2005
Location: Central Ohio, USA
Distribution: Fedora 7 x86_64 (home server), IPCop (home gateway), CentOS (work laptop), lots more at work.
Posts: 32
Original Poster
Rep:
|
Currently we use who, but due to samba sessions that tend to "hang" (as in they stay active after the user logs out), we're looking for something a bit more accurate.
|
|
|
All times are GMT -5. The time now is 10:15 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|