Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6616075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:32:21+00:00 2026-05-25T20:32:21+00:00

In ruby, I am trying to compare a list of URLs with a previous

  • 0

In ruby, I am trying to compare a list of URLs with a previous list of URLs, and get only the new ones.

I put the old list in a text file with one URL per line. I am reading the text file into an array like so:

oldLines = File.open('logfile.txt', 'r').readlines

I have an array of new values populated using the exact same method as the old list, and will probably have some overlap with the old list called ‘newLines’. I am trying to get only values that don’t match with the old list. Let’s say ‘newList’.length = 100 and ‘oldlist’.length = 95, and I know through visual inspection that something like 90 elements overlap between them.
Things I have tried:

newList = newList - oldList
#(newList | oldList) returns 195
#(newList & oldList) returns 0


newList.delete_if { |x| oldList.include?(x) }

In both scenarios, nothing gets deleted from newList. I know I am missing something here. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:32:21+00:00Added an answer on May 25, 2026 at 8:32 pm

    I did the following:

    a.txt

    http://yahoo.com
    http://google.com
    http://bing.com
    

    b.txt

    http://bing.com
    http://yahoo.com
    

    test.rb

    a = File.open('a.txt', 'r').readlines.map!(&:chomp)
    b = File.open('b.txt', 'r').readlines.map!(&:chomp)
    p a-b #=> ["http://google.com"]
    

    Without the chomp it fails because in a.txt I have http://yahoo.com\n while on b.txt I simply have http://yahoo.com without the \n at the end.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a new ruby/rails user trying to get my mac set up for the
I'm new to Ruby and trying to get it to run, but when I
I get this error when trying ruby script/console Rails requires RubyGems >= . Please
Using Ruby I'm trying to split the following text with a Regex ~foo\~\=bar =cheese~monkey
With ruby I'm trying to get format a date as such: 2009-10-01 Where I
I'm new to ruby/rails and trying to build a simple Projects / Tags app
I'm new to Ruby and am trying to pass a sort_by lambda to a
I am new to ruby and currently trying to operate on each character separately
I'm very new to ruby and trying some basic stuff. When I send HTTP
I am kinda new to Ruby and still trying to understand some of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.