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!

Need help to extract and join 2 tables with AWK script 1

Status
Not open for further replies.

curious01

Technical User
Feb 22, 2006
13
SG
Hi Everyone,
I am new to AWK and need alittle help! I have 2 tables and I need to extract and join them to one, based on a common identifier in both tables. Example:
Table 1:
S/N vial_ID S_ID value_1 value_2
1 v11 f1001 567 789
2 v12 f2087 786 567

Table2:
name S_ID typeA typeB
seed f7890 8 56
sap f1001 5 65
rap f7650 2 54
cap f2087 1 1

OUTPUT should look like:
vial_ID S_ID value_1 value_2 typeA typeB
v11 f1001 567 789 5 65
v12 f2087 786 567 1 1

I would be most grateful if someone could help me here. Thank you :)

curious K
 
A starting point:
awk '
NR==FNR{a[$3]=$2;b[$3]=$4;c[$3]=$5;next}
$2 in a{print a[$2],$2,b[$2],c[$2],$3,$4}
' Table1 Table2


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hello PH,
Thank you for your previous code. I tried and it works fine for my example. However when I tried on larger files it always generate no results or matches although there should be matches.Could you help me again? I am pretty new with AWK and am quite lost. Appreciate it if you could advice me here. Thanks again :)

curiousK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top