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!

How can I manage -extract and join large datasets 1

Status
Not open for further replies.

curious01

Technical User
Feb 22, 2006
13
SG
Hi
I am writing again with regards to my previous query (Need help to extract and join...). I tried the code provided by PH, it works fine with my example.
However, when I used it on my actual data tables it produced no result, although there should be matches between the 2 files. The 2 Tables have different number of records.My question: is this causing the problem I faced?
How can I modify the code to accomodate large data tables having different number of records.
Please please help.

Thank you :)

curious k
 
Hi futurelet,
below is the sample data(tab separated):

Table 1:
counter N_ID S_ID value1 value2 value3 value4....valu13
4418255 n-1a b0061
NULL NULL 1013 1035 1025 1019 NULL NULL 80 115 63 102 yes
4418256 n-1a b0396
NULL NULL 420 684 388 663 NULL NULL 39 86 38 86 yes
4418257 n-1a b1620
NULL NULL 483 801 474 787 NULL NULL 36 86 35 86 yes
4418258 n-1a b2172
NULL NULL 351 624 360 632 NULL NULL 37 85 36 84 yes
----------------------------------------------------------
Table2:
Name S_ID typeA typeB.....typeE
sta b0011 237 10 348 339 1175
stb b0012 196 20 265 276 914
stc b0061 134 8 179 200 623
std b0014 638 16 843 988 3001
ste b2172 376 17 534 550 1784
stf b0062 370 12 532 527 1809
stg b0017 102 6 157 145 519
sth b0018 69 6 97 96 339
sti b1620 50 4 65 70 244

 
Code:
# Skip header lines at beginning of files.
/^(counter|Name)/ { next }

# Reading first file?
ARGV[1]==FILENAME { a[$3]=$2; b[$3]=$4; c[$3]=$5; next }

$2 in a { print a[$2],$2,b[$2],c[$2],$3,$4 }
Save this code in file join.awk and run it with
[tt]awk -f join.awk Table1 Table2[/tt]
The output is
Code:
n-1a b0061 NULL NULL 134 8
n-1a b2172 NULL NULL 376 17
n-1a b1620 NULL NULL 50 4
 
Hi futurelet,
Thank you for the code and solving my problems.
It works fine :)

have a nice day
curious k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top