Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Script that doesn't print duplicate lines

Posted on 2013-10-28
Medium Priority
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 ="syslog.txt", "r")
        while (line = file.gets)
            if line['reserved']
                date = line[/\w+ +\d+ +\d+:\d+:\d+/]
                puts "#{counter}: #{date}"

Open in new window

Question by:djphillovesyou
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Author Comment

ID: 39609368
nvm. i found out what i was missing

Accepted Solution

djphillovesyou earned 0 total points
ID: 39609377
Working script:

class RestartMonitor
  found = []
  file ="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}"

Open in new window


Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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:…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

721 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