To find and merge two files

Hi All,

I have two files file1 and file2 as below.

cat file1

200000040;20.0
200000020;40.0
200000060;10
200000100;.0.5
----------------
cat file2

200000020
200000100
200000040
200000060
I want to merge this two files by comparing the field values of the first column of both the files. The merger file should be like this.

cat merged_file

200000020 ;40.0
200000100;0.5
200000040;20.0
200000060;10

Kindly suggest how to do this.

thanks in advance,
Giri.

Try...

 
awk -F";" 'NR==FNR{a[$1]}NR!=FNR{for(i in a)if(i==$1) print $0}' file2 file1

With grep:

grep -f fi1e2 file1

or with another awk solution:

awk -F";" 'NR==FNR{a[$1];next}$1 in a' file2 file1

With Perl:

perl -F\; -lane'
  next if @F > 1 and $_{$F[0]} = $_;
  print $_{$_};
  ' file1 file2

Thanks a lot to all.... It serves my requiment...

Thanks,
Giri