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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:26:42+00:00 2026-05-26T02:26:42+00:00

So, if the title didn’t make sense, here’s what I’m trying to do: I

  • 0

So, if the title didn’t make sense, here’s what I’m trying to do:

I have file1:

66.115.135.84:123.123.123.1
66.115.135.85:123.123.123.2
66.115.135.86:123.123.123.3
66.115.135.87:123.123.123.4
66.115.135.88:123.123.123.5
66.115.135.89:123.123.123.6
66.115.135.90:123.123.123.7
66.115.135.91:123.123.123.8
66.115.135.92:123.123.123.9
66.115.135.93:123.123.123.10
66.115.135.94:123.123.123.11
66.115.135.95:123.123.123.12
66.115.135.96:123.123.123.13
66.115.135.97:123.123.123.14

As you can see, it’s ip addresses, separated by a “:”

File2 is basically an apache virtual host entry, or httpd.conf file. It doesn’t really matter. Just know that file2 contains the ip addresses from the first column of file1 somewhere in there. And they need to be replaced by the second column of file1.

For some reason, this simple problem has left me bewildered. I’ve tried some pretty gnarly things, but keep getting stuck.

I know I can separate them using awk, and i know i could pipe that into sed to act on file2.

But I can’t seem to wrap my head around the best way to “map” column 1 to column 2 so that this can actually happen.

I’m willing to use perl, or ruby, or python, or really any method of achieving this, and I would very much like a brief explanation of how you are able to solve this.

Please ask for any clarification, and I’ll be glad to supply it.

Thanks so much in advance!

  • 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-26T02:26:43+00:00Added an answer on May 26, 2026 at 2:26 am

    Id use perl. Lets call it mapper.pl. Takes map file as an arg, and then maps stdin to stdout. So you use it like this

    perl mapper.pl file1 < file2 > file2.new
    

    The mapper.pl program is something like:

    use strict;
    use warnings;
    
    # Prototypes
    sub readMap($);
    
    # Main program
    {
        if( scalar(@ARGV) != 1 )
        {
            die "usage: mapper.pl mapfile";
        }
        my %map = readMap( $ARGV[0] );
        while( my $line = <STDIN> )
        {
            foreach my $old ( keys(%map) )
            {
                my $old_re = $old;
                # Escape metacharacters
                $old_re =~ s/\W/\\$&/g;
                $line =~ s/$old_re/$map{$old}/g;
            }
            print $line;
        }
    } # END main
    
    sub readMap($)
    {
        my $mapname = $_[0];
        my %map;
        open( MAPFILE, "<$mapname" ) || die "open($mapname): $!";
        while( my $line = <MAPFILE> )
        {
            if( $line =~ /^\s*([^:]+):(.*?)\s*$/ )
            {
                $map{$1} = $2;
            }
            else
            {
                warn "Invalid line: $line";
            }
        }
        close( MAPFILE );
        return( %map );
    } # END readMap
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I understand the Title didn't make any sense so here I've tried to
I know that title didn't make sense, Im sorry! Its hard to word what
Sorry if the title didn't make much sense. I'm making a Chip's Challenge style
Sorry if the title didn't make any sense. Currently, the following parameters on the
The title attribute didn't shows. If you have a tip using another attribute type,
i didn't really know how to title this question, but here's a thing that
Sorry if that title didn't explain it well. Here is the table... (source: alexanderdickson.com
Title might be confusing, didn't quite know how to put it. Here's what i
The title might be ambiguous, didn't know how else to word it. I have
Folks, I know I didn't phrase that title very well, but here's the scenario.

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.