Solved

Script that doesn't print duplicate lines

Posted on 2013-10-28
2
215 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
ID: 39609368
nvm. i found out what i was missing
0
 

Accepted Solution

by:
djphillovesyou earned 0 total points
ID: 39609377
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What is Ruby programming? 7 433
Ruby script to take single regular expression and search directory 1 553
How to extract values from string in Ruby on Rails 3 407
Ruby process xml 1 217
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 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