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!

Append text to end of lines in a file from another file 1

Status
Not open for further replies.
Apr 13, 2004
316
US
File 1:
ce0: 192.168.1.100
bge0: 192.168.1.101
bge1: 192.168.3.204

File 2:
Saturn-db 192.168.9.230
Neptune-db 192.168.1.100
Pluto-mgt 192.168.1.101
Venus-db 192.168.2.222
Mars-mgt 192.168.3.204

What I want:
ce0: 192.168.1.100 Saturn-db
bge0: 192.168.1.101 Pluto-mgt
bge1: 192.168.3.204 Mars-mgt

I have done this before in ksh but there has to be an easier method with sed and/or awk.

Thanks!
 
The what I want for the first line should be Neptune-db not Saturn-db.

Thanks.
 
Try

BEGIN {
if (!fn) fn="file2.dat"
while ((getline < fn) > 0) a[$2]=$1
close(fn)
}
{
print $0, a[$2]
}

CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top