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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

join 1

Status
Not open for further replies.

kHz

MIS
Dec 6, 2004
1,359
US
Does anyone know how to use the join command? I have been trying and am not having any luck.

file1:
host1 [tab] xx.xxx.xx.xxx [tab] ce1
host2 [tab] xx.yyy.yy.yyy [tab] bge2
.
.
.

file2:
host1-app [tab] xx.xxx.xx.xxx
host4-mgt [tab] xx.xxx.yy.xxx
host2-mgt [tab] xx.yyy.yy.yyyy
.
.
.

What I want is to join the two files based on the IP fields, which are $2 in file1 and $2 in file2.

The result would be:
host1 [tab] xx.xxx.xx.xxx [tab] ce1 [tab] host1-app
host2 [tab] xx.yyy.yy.yyy [tab] bge2 [tab] host2-mgt

Thanks.
 
Never mind. I was able to get it using something in awk from PHV.
 
Provided the 2 files are sorted on the IP field:
join -j 2 -o 1.1 1.2 1.3 2.1 file1 file2

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks, I used your solution for this problem that I had asked another day in the awk forum but couldn't get it to work. After using your suggeston of nawk today for my other thread, that is what I used for this problem and nawk worked.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top