How to Sort ip addresses and merge two files in efficent manner using perl or *nix commands?

Posted by berkay on Stack Overflow See other posts from Stack Overflow or by berkay
Published on 2010-12-29T17:02:23Z Indexed on 2010/12/29 18:54 UTC
Read the original article Hit count: 387

Filed under:
|
|
|

(*) This problem should be done in perl or any *nix commands.

i'm working on a program and efficiency matters.The file1 consists ip addresses and some other data:

index ipsrc     portsrc  ip dest     port src
8 128.3.45.10 2122 169.182.111.161 80 (same ip src and dst)
9 128.3.45.10 2123 169.182.111.161 22 (same ip src and dst)
10 128.3.45.10 2124 169.182.111.161 80 (same ip src and dst)
19 128.3.45.128 62256 207.245.43.126 80

and other file2 looks like (file1 and file2 are in different order)

128.3.45.10 ioc-sea-lm 169.182.111.161 microsoft-ds 0 0 3 186 3 186 
128.3.45.10 hypercube-lm 169.182.111.161 https 0 0 3 186 3 186
128.3.44.112 pay-per-view 148.184.171.6 netbios-ssn 0 0 3 186 3 186
128.3.45.12 cadabra-lm 148.184.171.6 microsoft-ds 0 0 3 186 3 186

1- SORT file1 using IP address in second column and SORT file2 using IP address in first column

2- Merge the 1st, 3rd and 5th columns of File1 with File 2

i need to create a new file which will look:

128.3.45.10 ioc-sea-lm 169.182.111.161 microsoft-ds 0 0 3 186 3 186 --> 2122 80 8
128.3.45.10 hypercube-lm 169.182.111.161 https 0 0 3 186 3 186 --> 2123 22 9
128.3.44.112 pay-per-view 148.184.171.6 netbios-ssn 0 0 3 186 3 186 --> * * *
128.3.45.12 cadabra-lm 148.184.171.6 microsoft-ds 0 0 3 186 3 186 --> * * *

basically port numbers and index number will be added.

© Stack Overflow or respective owner

Related posts about perl

Related posts about unix