Operating System - HP-UX
1833744 Members
3004 Online
110063 Solutions
New Discussion

How to merge two files with pattern matching using Shell/AWk ??

 
SOLVED
Go to solution
Praveen Hari
Advisor

How to merge two files with pattern matching using Shell/AWk ??

Hi,

I have two files with following content:
file1:
xxx1 100
xxx2 200
xxx3 100
file2:
xxx2 275
xxx1 230
xxx3 150

I want to produce a new file with following content:
file3:
xxx1 100 230 xxx1.bif
xxx2 200 275 xxx2.bif
xxx3 100 150 xxx3.bif

Basically lines may not be matching in file1 and file2. But they will exist in same pattern. I want to combine them with numbers from file1 and file2 into a third file.

I hope some Shell/AWK guru can help me here.
Thanks
6 REPLIES 6
Rodney Hills
Honored Contributor
Solution

Re: How to merge two files with pattern matching using Shell/AWk ??

Do a man on "join".

join file1 file2

You may have to sort each file first.

HTH

-- Rod Hills
There be dragons...
Praveen Hari
Advisor

Re: How to merge two files with pattern matching using Shell/AWk ??

How do you sort a file ?
Praveen Hari
Advisor

Re: How to merge two files with pattern matching using Shell/AWk ??

How do you sort a file ?
Praveen Hari
Advisor

Re: How to merge two files with pattern matching using Shell/AWk ??

How do you sort a file ?
Brian Crabtree
Honored Contributor

Re: How to merge two files with pattern matching using Shell/AWk ??

"sort" =)
Praveen Hari
Advisor

Re: How to merge two files with pattern matching using Shell/AWk ??

Thanks all. It worked.