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!

About associative array 2

Status
Not open for further replies.

abdu22

Programmer
Sep 13, 2005
14
FR
Hello,

I have two files:

file1
----
Src
BdU
BoH
BFL
BFR
BdW
BLL
BLR
Bdr

file2
---
Src Lvr
BdU 1.906e-16
BdW 4.199e-16
Bdr 2.869e-16
BLL 1.975e-16
BLR 2.343e-16
BoH 2.625e-15
BFL 3.890e-16
BFR 4.756e-16
BoL 3.091e-16
BoR 3.711e-16
Brn 2.224e-16
Car 1.542e-12
Col 1.034e-12

if $1 from file1 == $1 from file2 ==> print $1" "$2 from file2...
I am trying this code:
awk 'FNR==NR {t1=$1; next}
{if (t1=$1) print ($1" "$2)}' file1 file2

but it prints all the values in file2!!!!...

can someone help me please?
 
Perhaps
Code:
awk 'FNR==NR {t1[$1]=$1; next}
{if (t1[$1]==$1) print ($1" "$2)}' file1 file2
Note the == in the if comparison.

--
 
or simply....:
Code:
awk 'FNR==NR {t1[$1]=$1; next} $1 in t1' file1 file2

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top