Core iTOps Tube

Wednesday, 16 May 2012

Replace column that matches specific pattern, with column data from another file

Can anyone please help with this? I have 2 files as given below.

If 2nd column of file1 has pattern foo1@a, find the matching 1st column in file2 & replace 2nd column of file1 with file2's value.




Code:


file1



abc_1    foo1@a  ....

abc_1    soo2@a ...

def_2    soo2@a  ....

def_2    foo1@a .....

ghi_3    foo1@a .....

ghi_3    soo1@a


file2




Code:


def_2    foo2@a

def_2    soo2@a

abc_1    foo3@a

abc_1    soo1@a       

ghi_3      foo2@a

ghi_3    soo1@a


Required output ( file1 modified to be):




Code:


abc_1    foo3@a

abc_1    soo2@a

def_2    soo2@a

def_2    foo2@a

ghi_3    foo2@a

ghi_3    soo1@a










Moderator's Comments:









Code tags for code, please.





No comments:

Post a Comment