Solved

Script that doesn't print duplicate lines

Posted on 2013-10-28
2
213 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Rails 3.0 Routing 3 626
Ruby problem with blocks 5 320
Record Login Time 8 489
What is Ruby programming? 7 431
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…
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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