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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk or any other means to find IP (File1 / MAC (File2)) entries and putting them on File3
# 1  
Old 05-14-2015
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:
Code:
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:
Code:
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:
Code:
1.1.1.1   4851.b7d8.bed1

Thank you

Jim

Last edited by rbatte1; 05-14-2015 at 11:43 AM.. Reason: Added CODE tags
# 2  
Old 05-14-2015
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
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 05-14-2015
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 :
Code:
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



Moderator's Comments:
Mod Comment
Please wrap all code, files, input & output/errors in CODE tags.
It makes the easier to read and preserves multiple spaces for indented code and fixed-width data.

Last edited by redred; 05-14-2015 at 12:05 PM.. Reason: Added CODE tags
# 4  
Old 05-14-2015
A good start, but you must compare with $2 in the 2nd run.
Code:
awk 'NR==FNR{buff[$1]=1;next} {if(buff[$2]==1) print $2,$4}'

A bit more advanced is
Code:
awk 'NR==FNR{buff[$1];next} ($2 in buff){print $2,$4}'


Last edited by MadeInGermany; 05-14-2015 at 12:35 PM..
This User Gave Thanks to MadeInGermany For This Post:
# 5  
Old 05-14-2015
THANK YOU!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to search field2 in file2 using range of fields file1 and using match to another field in file1

I am trying to use awk to find all the $2 values in file2 which is ~30MB and tab-delimited, that are between $2 and $3 in file1 which is ~2GB and tab-delimited. I have just found out that I need to use $1 and $2 and $3 from file1 and $1 and $2of file2 must match $1 of file1 and be in the range... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. UNIX for Dummies Questions & Answers

Copy(append ) the contents of file1 and file2 to file3

Platform : Oracle linux 6.5 I have two log files with the following contents # ls -l total 8 -rw-r--r--. 1 root root 75 Dec 10 20:55 myLogfile1.log -rw-r--r--. 1 root root 51 Dec 10 20:57 myLogfile2.log # # cat myLogfile1.log hello world jaded zombies acted quaintly but kept driving... (9 Replies)
Discussion started by: kraljic
9 Replies

3. Shell Programming and Scripting

Compare and find records of file1 not in file2

hi.. i am using solaris system and ksh and using nawk to get records of file1 not in file2(not line by line comparison). code i am using is nawk 'NR==FNR{a++} !a {print"line:" FNR"->" $0} ' file2 file1 same command with awk runs perfectly on darwin kernel(mac) but in solaris it does line by... (2 Replies)
Discussion started by: Abhiraj Singh
2 Replies

4. Shell Programming and Scripting

awk read in file1, gsub in file2, print to file3

I'm trying to use awk to do the following. I have file1 with many lines, each containing 5 fields describing an individual set. I have file2 which is a template config file with variable space holders to be replaced by the values in file1. I would like to substitute each set of values in file1 with... (6 Replies)
Discussion started by: msmehaffey
6 Replies

5. Shell Programming and Scripting

Performance issue with fgrep -vf file1 file2>file3

Hi all, My requirement is that i have two files file1 and file2. file1 content is present in file2. i want to have a final which will have file2 contents but not the contents of file1 so I am running below command. fgrep -vf file1 file2>file3 no of records in file1 is 65282 no of records... (10 Replies)
Discussion started by: Lakshman_Gupta
10 Replies

6. UNIX for Dummies Questions & Answers

if matching strings in file1 and file2, add column from file1 to file2

I have very limited coding skills but I'm wondering if someone could help me with this. There are many threads about matching strings in two files, but I have no idea how to add a column from one file to another based on a matching string. I'm looking to match column1 in file1 to the number... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

7. Shell Programming and Scripting

how to find string from file1 in file2

hi; i am looking for simple search script that find string from file1 in file 2 file 1 contain a loot of string like: 204080111111111 204080222222222 204080333333333 in each row and i would like to take the first row for example 204080111111111 from file1 and find it in file2 when it... (1 Reply)
Discussion started by: kpinto
1 Replies

8. UNIX for Dummies Questions & Answers

cat file1 file2 > file3

file1 has pgap500 500 file2 has bunch of data cat file1 file2 > file3 cp file2 file3.dat then vi pgap500 500 onto 1st line compare file3 and fil3.dat, they are not the same. any idea ? the 1st line, i want to put pg500 xxx ---------- Post updated at 07:35 AM ---------- Previous... (2 Replies)
Discussion started by: tjmannonline
2 Replies

9. Shell Programming and Scripting

Find numbers from File1 within File2

Hi all, Please your help with this. I have 2 files, File_1-->contains a column of N numbers File_2-->contains many lines with other info and numbers from File_1 within it. I would like to get from File_2 all the lines containing within the same line each of N numbers from File_1... (4 Replies)
Discussion started by: cgkmal
4 Replies

10. UNIX for Dummies Questions & Answers

echo "ABC" > file1.txt file2.txt file3.txt

Hi Guru's, I need to create 3 files with the contents "ABC" using single command. Iam using: echo "ABC" > file1.txt file2.txt file3.txt the above command is not working. pls help me... With Regards / Ganapati (4 Replies)
Discussion started by: ganapati
4 Replies
Login or Register to Ask a Question