Solved

Script that doesn't print duplicate lines

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to SSH interactive Session In ruby Ruby 3 1,152
no images after rails 3.1 deploy 7 224
What is Ruby programming? 7 426
How much to charge--small Ruby on Rails project 13 781
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 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