-1

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

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

2 Answers 2

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 
1
  • This is slow and inefficient... Use the right tools for this job: join or awk. Commented Sep 24, 2015 at 9:58

Not the answer you're looking for? Browse other questions tagged .