Comparing the two files using awk script

Hi all,
Can you please help me to find out that where is the problem in my script or either my way of writing the shell command on the prompt is not right? Actually, I want to compare the second column "$1" of the file "t1" with all the columns of second file "t2", if there is a match then the script should return the matched column. But currently my script is printing the whole data of the first file "t1". I will highly appreciate any feedback and suggestions. I badly need to fix this problem as soon as possible; therefore any quick response will be acknowledged.

File1 "t1":

   7 real_name
   8 pa_name
   9 make_server_info_pw
   9 passon
  11 mapped_name
  11 nt_status
  13 passon
  15 p
  17 server_info
  18 p

File2 "t2":

   1 CHECK_DECLS
   1 True
   1 conf
   1 headers
   1 reverse
   1 real_name 

Script:

 #!/usr/bin/awk
  BEGIN {
  FS= � �;
  OFS=� �; 
  RS= �\n�;
  ORS=�\n�;
  }
  NR==FNR
  {
  arr[$1]; next 
  }
  $1 in arr {
  print $1;  
  } file1 file2 

Shell command to execute the script

awk -f sim.awk t1 t2 

Desired out put

 real_name

Firstly, please use code tags for sample data and code. See video tutorial. Secondly, please post desired output for the sample input files.

---------- Post updated 02-11-12 at 02:40 PM ---------- Previous update was 02-10-12 at 03:21 PM ----------

awk 'NR==FNR{a[$2]=1;next}$2 in a{print $2}' t1 t2
1 Like

Thanks Franklin52 for editing my request and Bartus11 for the script.

Bartus11, please can you explain the following parts of the script?

what is the meaning of this ' before NR==FNR
Why you put the values of file1 in array "a" and why you have assigned the value 1 to column2  a[$2]=1
What is the meaning of this pattern $2 in a
Why you end the program with another single quote '

One again many thanks :b: