Solved

Script that doesn't print duplicate lines

Posted on 2013-10-28
2
197 Views
Last Modified: 2013-10-29
what could i add to this script that would not add the duplicated lines that are in the .txt file.

class RestartMonitor
    counter = 1
            file = File.new("syslog.txt", "r")
        while (line = file.gets)
            if line['reserved']
                date = line[/\w+ +\d+ +\d+:\d+:\d+/]
                puts "#{counter}: #{date}"
                
            end        
        end
    end

Open in new window

0
Comment
Question by:djphillovesyou
  • 2
2 Comments
 

Author Comment

by:djphillovesyou
Comment Utility
nvm. i found out what i was missing
0
 

Accepted Solution

by:
djphillovesyou earned 0 total points
Comment Utility
Working script:

class RestartMonitor
  found = []
  file = File.new("syslog.txt", "r")
  while (line = file.gets)
    if line['restarting']
      date = line[/\w+ +\d+ +\d+:\d+:\d+/]
      if !found.include? date
        found << date 
        puts "#{date}"
      end
    end        
  end
end

Open in new window

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I recently rediscovered rails when I needed a holiday project and decided to build a management dashboard for the company where I work.  With it being a project done in my free time, I could focus my time on learning the basics rather than trying to…
In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below: http://www.rubytips.org/2008/05/13/accessing-windows-api-fro…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now