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!

Append columns from file to another if columns match 2

Status
Not open for further replies.

blarneyme

MIS
Jun 22, 2009
160
US
Not sure how to do this. There are a few thousand lines in file2 and a couple hundred lines in file1. Each line is a different hostname in each file.

file1:
v440,x-1-1,hostname1,80-9293w23,s/n 2222,yes,0,0,1.1,07/12/2009,07/23/2009,none,2,any,many

file2:
a10,,hostname1,e2900,renamed from hostname2

What I would like is if the hostname in file2 (column3) matches hostname in file1 (column 3) then append "e2900" column and "renamed from hostname2" column to the end of the line of file1, like this:

v440,x-1-1,hostname1,80-9293w23,s/n 2222,yes,0,0,1.1,07/12/2009,07/23/2009,none,2,any,many,e2900,renamed from hostname2
 
A starting point:
Code:
awk -F, 'NR==FNR{a[$3]=","$4","$5;next}{print $0""a[$3]}' file2 file1

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top