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

  • Home
  • SEARCH
  • 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 3277834
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:24:49+00:00 2026-05-17T19:24:49+00:00

I originally asked this question: Regular Expression in gVim to Remove Duplicate Domains from

  • 0

I originally asked this question: Regular Expression in gVim to Remove Duplicate Domains from a List

However, I realize I may be more likely to find a working solution if I “broaden my scope” in terms of what solution I’m willing to accept.

So, I’ll rephrase my question & maybe I’ll get a better solution…here goes:

I have a large list of URLs in a .txt file (I’m running Windows Vista 32bit) and I need to remove duplicate DOMAINS (and the entire corresponding URL to each duplicate) while leaving behind the first occurrence of each domain. There are roughly 6,000,000 URLs in this particular file, in the following format (the URLs obviously don’t have a space in them, I just had to do that because I don’t have enough posts here to post that many “live” URLs):

http://www.exampleurl.com/something.php
http://exampleurl.com/somethingelse.htm  
http://exampleurl2.com/another-url  
http://www.exampleurl2.com/a-url.htm  
http://exampleurl2.com/yet-another-url.html  
http://exampleurl.com/  
http://www.exampleurl3.com/here_is_a_url  
http://www.exampleurl5.com/something

Whatever the solution is, the output file using the above as the input, should be this:

http://www.exampleurl.com/something.php  
http://exampleurl2.com/another-url  
http://www.exampleurl3.com/here_is_a_url  
http://www.exampleurl5.com/something

You notice there are no duplicate domains now, and it left behind the first occurrence it came across.

If anybody can help me out, whether it be using regular expressions or some program I’m not aware of, that would be great.

I’ll say this though, I have NO experience using anything other than a Windows OS, so a solution entailing something other than a windows program, would take a little “baby stepping” so to speak (if anybody is kind enough to do so).

  • 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-17T19:24:51+00:00Added an answer on May 17, 2026 at 7:24 pm

    Regular expressions in Python, very raw and does not work with subdomains. The basic concept is to use dictionary keys and values, key will be domain name, and value will be overwritten if the key already exists.

    import re
    
    pattern = re.compile(r'(http://?)(w*)(\.*)(\w*)(\.)(\w*)')
    urlsFile = open("urlsin.txt", "r")
    outFile = open("outurls.txt", "w")
    urlsDict = {}
    
    for linein in urlsFile.readlines():
        match = pattern.search(linein)
        url = match.groups()
        domain = url[3]
        urlsDict[domain] = linein
    
    outFile.write("".join(urlsDict.values()))
    
    urlsFile.close()
    outFile.close()
    

    You can extend it to filter out subdomains, but the basic idea is there I think. And for 6 million URLs might take quite a while in Python…

    Some people, when confronted with a
    problem, think “I know, I’ll use
    regular expressions.” Now they have
    two problems. −−Jamie Zawinski, in
    comp.emacs.xemacs

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

Sidebar

Related Questions

Following on from this question I asked yesterday: Can I shorten this regular expression?
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost
I originally asked this question on RefactorMyCode , but got no responses there... Basically
I originally asked this question , but in finding an answer, discovered that my
This question originally asked which is the best method for uploading files via SFTP
This question originally asked (wrongly) what does | mean in Python, when the actual
Disclaimer This question is a repost. I originally asked it here . While there
I asked this question to get to know how to increase the runtime call
I originally asked a question along these lines using Regex but was recommended to
This is an offshoot question that's related to another I asked here . I'm

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.