-1

This question already has an answer here:

Need to combine two file data having same column 1 but different column 2 values.

One file has data:

AP               3492
BJ               4995
GJ               3810
MH               5800
UK               5148
UP               8096

Second file has data

AP               3372
BJ               4709
GJ               3728
MH               5403
UK               5154
UP               7724

Now want data in below format

AP 3492 3372
BJ 4995 4709
GJ 3810 3728
MH 5800 5403
UK 5148 5154
UP 8096 7724

Also require the data in html format on mail

marked as duplicate by John WH Smith, don_crissti, Archemar, Anthon, taliezin Sep 24 '15 at 10:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • iam working on UNIX system. – abhishek Sep 24 '15 at 9:15
1

Use the join command:

join -j 1 file1 file2

The -j 1 means to use the first column in each file to match the data. You can also specify e.g. -1 3 -2 2 meaning "use column 3 from the first file, and match it with column 2 from the second file.

0

I got an answer using read. Let's say your files are a.txt and b.txt. You could do:

 while read fp sp; do echo `grep $fp a.txt` $sp  ; done < b.txt 
  • This is slow and inefficient... Use the right tools for this job: join or awk. – don_crissti Sep 24 '15 at 9:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.