Hi,
I know that this topic has been discussed in the past and I've tried to follow all the guidelines. Anyhow, I following describe my problem.
I have a file (file1 , no. records = 67) containing pairs of IP addresses as follows (with single space as delimiter between the fields):
example of file1
1.2.3.4 123.45.2.1
1.2.3.4 68.32.1.4
........ ............
and another file (file2) which is much larger in size (no. records = 500 000) that the first two fields are still IP addresses (single space as delimiter in all fields) that they do also provide some other information in the subsequent fields (48 fields on every record/line)...as follows
example of file2
1.2.3.4 123.45.2.1 53 4000 2.5 30 21 43 .....
1.2.3.4 68.32.1.4 500 80 3.7 40 22 10 .....
1.2.3.4 50.44.66.1 40 30 8.5 29 11 10 .....
Since the first field is the same, I want to compare the second field of file1 with the second field of file2 and if matched to print the whole record (with all the 48 fields) from file2 into a new file (i.e. file3)
I've tried to do with the following one-liner
awk 'NR==FNR{a[$2]=$0;next}a[$2]{$0=a[$2]}1' file2 file1 > file3
which provides me a result but it only gives me 67 records in the newly created file3...by going visually through file2 I could see more matches...any suggestions?
Thanks in advance!