Dear all,
I use following codes to join two tab delimited files and print out wanted columns. for both files, the key is at the 4th cols. the codes work for following two files, let me call them "wf1" and "wf2"
first the codes:
awk -F"\t" '{while((getline<"'wf2'")>0) f2[$4]=$4;OFS="\t"} {if (f2[$4]) print f2[$4],$1,$4}' wf1
# wf1
meta weight data country desc
gold 1 1986 USA American Eagle
gold 1 1908 Austria-Hungary Franz Josef 100 Korona
silver 10 1981 USA ingot
gold 1 1984 Switzerland ingot
gold 1 1979 RSA Krugerrand
#wf2
meta weight data country desc
GOLD 1 1979 RSA Krugerrand
GOLD 1 1908 Austria-Hungary Franz Josef 100 Korona
SILVER 10 1981 USA ingot
GOLD 1 1984 Switzerland ingot
GOLD 1 1988 Canada Maple Leaf
PLATI 100 2000 PRC PANDA-MATCH
# the output
USA gold USA
Austria-Hungary gold Austria-Hungary
USA silver USA
Switzerland gold Switzerland
RSA gold RSA
However, it doesn't work for following two files, let me call them "ff1","ff2"
codes: (for this two tab delimited files, key is the first col for both file, therefore $4 changed to $1, and I want all cols in all of them, so " f2[$1]=$0", and "print f2[$1],$0 " )
awk -F"\t" '{while((getline<"'ff2'")>0) f2[$1]=$0;OFS="\t"} {if (f2[$1]) print f2[$1],$0}' ff1
# ff1
CAS NA 3
IBM 6 5
ATX 7 NA 6
XXX 8 NA
BLC NA
ACN 9 10 7
AGE 10 NA
SMC 11 12 8
CAS 12 13 9
# ff2
AGE 13 0
BLC 13 1
CAS 7 0
SMC 6 1
ATX 6 1
# output
ATX 6 1 ATX 6 1
the match failed and the output weird, I've been drived nuts by this, could you help me out.
Thank you
Warm Regards
Will
I use following codes to join two tab delimited files and print out wanted columns. for both files, the key is at the 4th cols. the codes work for following two files, let me call them "wf1" and "wf2"
first the codes:
awk -F"\t" '{while((getline<"'wf2'")>0) f2[$4]=$4;OFS="\t"} {if (f2[$4]) print f2[$4],$1,$4}' wf1
# wf1
meta weight data country desc
gold 1 1986 USA American Eagle
gold 1 1908 Austria-Hungary Franz Josef 100 Korona
silver 10 1981 USA ingot
gold 1 1984 Switzerland ingot
gold 1 1979 RSA Krugerrand
#wf2
meta weight data country desc
GOLD 1 1979 RSA Krugerrand
GOLD 1 1908 Austria-Hungary Franz Josef 100 Korona
SILVER 10 1981 USA ingot
GOLD 1 1984 Switzerland ingot
GOLD 1 1988 Canada Maple Leaf
PLATI 100 2000 PRC PANDA-MATCH
# the output
USA gold USA
Austria-Hungary gold Austria-Hungary
USA silver USA
Switzerland gold Switzerland
RSA gold RSA
However, it doesn't work for following two files, let me call them "ff1","ff2"
codes: (for this two tab delimited files, key is the first col for both file, therefore $4 changed to $1, and I want all cols in all of them, so " f2[$1]=$0", and "print f2[$1],$0 " )
awk -F"\t" '{while((getline<"'ff2'")>0) f2[$1]=$0;OFS="\t"} {if (f2[$1]) print f2[$1],$0}' ff1
# ff1
CAS NA 3
IBM 6 5
ATX 7 NA 6
XXX 8 NA
BLC NA
ACN 9 10 7
AGE 10 NA
SMC 11 12 8
CAS 12 13 9
# ff2
AGE 13 0
BLC 13 1
CAS 7 0
SMC 6 1
ATX 6 1
# output
ATX 6 1 ATX 6 1
the match failed and the output weird, I've been drived nuts by this, could you help me out.
Thank you
Warm Regards
Will