Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk searching between two files

Status
Not open for further replies.

mac7777

Programmer
Mar 12, 2008
2
FR
hi there,
im writing some scripts in awk; in few words i have a list from router (mac address- ip address) and the second list with only the mac addresses.
the thing is that i want search list from router for the first mac address; if found - print the ip address, if not print error; then search the router list for the second mac address, if found print ip.. etc.
summarize: i have two files, router and macs like this (respectivly)
43:43:43:43:43 10.0.0.3
43:43:43:43:45 10.0.0.4
43:43:43:43:44 10.0.0.5
43:43:43:43:46 10.0.0.6
and
43:43:43:43:43
43:43:43:43:46

and as result im looking for:
43:43:43:43:43 10.0.0.3
43:43:43:43:46 10.0.0.6

im doing it in this way:
cat router | awk '{
getline tmp < macs
if ($1 = tmp) print
}'

i know, it is wrong, that is why im posting

any ideas?

cheers.
 
grep -f macs router

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
yes, simplest solutions are the best.
thank you for opening my eyes. ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top