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!
Id use perl. Lets call it
mapper.pl. Takes map file as an arg, and then mapsstdintostdout. So you use it like thisThe
mapper.plprogram is something like: