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 8584599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:48:43+00:00 2026-06-11T21:48:43+00:00

Below is a list of hostnames that is stored in a text file. web1.maxi.com

  • 0

Below is a list of hostnames that is stored in a text file.

web1.maxi.com
web3.maxi.com
web4.maxi.com
web5.maxi.com
web6.maxi.com
web7.maxi.com
web8.maxi.com
web9.maxi.com
web11.maxi.com

for the sake of displaying it shortly it needs to be parsed and rewritten/displayed as

web[1,3-9,11].maxi.com

can you guys help me on this, any suggestions will be helpful.

  • 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-06-11T21:48:44+00:00Added an answer on June 11, 2026 at 9:48 pm

    With perl you can use the Set::IntSpan module for compressing the number sequence.

    The below solution can handle mixed and unordered site listings.

    infile

    web3.maxi.com
    web4.maxi.com
    web5.maxi.com
    mail1.mexi.com
    web6.maxi.com
    web9.maxi.com
    web9.maxi.com
    
    web11.maxi.com
    mail3.mexi.com
    web7.maxi.com
    mail4.mexi.com
    mail25.mexi.com      
      mail26.mexi.com
    mail27.mexi.com
    mail28.mexi.com
      web8.maxi.com
    mail29.mexi.com
    mail110.mexi.com
    web1.maxi.com
    

    parse.pl

    #!/usr/bin/perl -l
    
    use Set::IntSpan;
    use File::Slurp qw/slurp/;
    
    $str = slurp(\*STDIN);
    
    # Remove redundant whitespace
    chop $str;
    $str =~ s/^[\t ]+|[\t ]+$//gm;
    $str =~ s/\R+/\n/g;
    
    # Copy $str so we can match numbers in it without disturbing the loop
    $nums = $str;
    
    # Parse lines in $str in sequence
    while($str =~ /^(.*)$/gm) {
      $line = $1;
    
      # Extract bits before and after number
      ($pre, $post) = $line =~ /([^\d]+)\d+(.*)$/m;
    
      # Check if its been printed already
      next if $seen{$pre . $post};
    
      # If not, extract numbers
      @numbers = $nums =~ /$pre(\d+)$post/g;
    
      print $pre . "[" 
            . Set::IntSpan->new(@numbers)->run_list()
            . "]" . $post;
    
      $seen{$pre . $post} = 1;
    }
    

    Run it like this:

    perl parse.pl < infile
    

    Output:

    web[1,3-9,11].maxi.com
    mail[1,3-4,25-29,110].mexi.com
    

    The perhaps cryptic @numbers = $nums =~ /$pre(\d+)$post/g expands to an array of items matched by the regular expression and saves it in @numbers.

    Note that this solution loads the whole file into memory.

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

Sidebar

Related Questions

I'm appending to a list then throwing that list into a function below: List<ItemBean>
I want to do the below list iteration in django templates: foo = ['foo',
In below data list represents set of question's and answer, How to check whether
I have the following code below for list into master page <div id=header> <ul>
I would like to place my div below the list, but actually it is
Im getting the following error for the piece of code below : expression list
I have the below java code: List<SomePojo> list = new ArrayList<SomePojo>(); //add 100 SomePojo
When I click on the list-item below (li) I change the id of it
I have a list (see below) contained in a window. The window's DataContext has
I've put together the code below that lists and allows me to delete members.

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.