awk or any other means to find IP (File1 / MAC (File2)) entries and putting them on File3

Hi everyone,
I would like to complete the following could you please find some time and help me to achieve below:

File 1 has a list of IP address (more than 1k)
File1:

1.1.1.1
2.2.2.2
1.1.1.2
3.3.3.3
2.3.3.2

File 2 has content like this:

Internet  11.165.91.244           0   Incomplete      ARPA
Internet  11.254.42.222           0   Incomplete      ARPA
Internet  11.65.27.80             0   Incomplete      ARPA
Internet  11.254.41.221           0   Incomplete      ARPA
Internet  172.30.241.67           2   0050.b653.b670  ARPA   Vlan101
Internet  10.255.51.198           0   e4d3.f1cf.cfca  ARPA   Vlan86
Internet  1.1.1.1                 0   4851.b7d8.bed1  ARPA   Vlan340

I would like to find all from File1 that are on File2 and copy output including column 4 of File 2 to look like this:

1.1.1.1   4851.b7d8.bed1

Thank you

Jim

Dear redred,

I have a few to questions pose in response first:-

  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)

Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.

We're all here to learn and getting the relevant information will help us all.

Robin

1 Like

Dear Robin,
Thanks for replying, its not part of assignment . I have so much of this data that i started to seek help to make it done via script.

I have tried this one below and nothing happens... the file3.txt is empty :

awk 'NR==FNR{buff[$1]=$1;next} {if(buff[$1]!="") print buff[$1]}' file1.txt file2.txt > file3.txt

If someone could help me out that would be great.
Thanks

A good start, but you must compare with $2 in the 2nd run.

awk 'NR==FNR{buff[$1]=1;next} {if(buff[$2]==1) print $2,$4}'

A bit more advanced is

awk 'NR==FNR{buff[$1];next} ($2 in buff){print $2,$4}'
1 Like

THANK YOU!!!