Unix/Linux Go Back    



Replacing first field of file2 with the second filed of file1 for matching cases

Shell Programming and Scripting




Kindly Note - This is a Single User Post by Forum Member ailnilanjan Regarding:
Replacing first field of file2 with the second filed of file1 for matching cases.
Please Follow The Primary Link Above to View the Full Discussion.

   
Old Unix and Linux 11-06-2014   -   Original Discussion by ailnilanjan
ailnilanjan's Unix or Linux Image
ailnilanjan ailnilanjan is offline
Registered User
 
Join Date: Jan 2007
Last Activity: 22 April 2017, 11:17 AM EDT
Posts: 48
Thanks: 25
Thanked 0 Times in 0 Posts
Replacing first field of file2 with the second filed of file1 for matching cases

Dear All,

Need your help..Linux

I am not regular on shell scripts..Linux

I have 2 files..


Content of file1



Code:
cellRef 4};"4038_2_MTNL_KALAMBOLI"
 cellRef 1020};"4112_3_RAINBOW_BLDG"
 cellRef 134};"4049_2_TATA_HOSPITAL"
 cellRef 1003};"4242_3_HITESH_CONSTRUCTION"
 cellRef 744};"5035_2_SHAHI_NOORANI_MASJID"
 cellRef 622};"4614_3_SHYAM_NIVAS_DCS"
 cellRef 1080};"4303_1_LODHA_HEAVEN"
 cellRef 394};"4502_1_NAVKANTLAL"
 cellRef 1884};"4323_2_COMMERCE_CENTER"
 cellRef 888};"4260_1_BOLENATH_DAIRY"
 cellRef 945};"4240_1_SHARIFA_MANZIL"
 cellRef 922};"4231_2_NASHEMAN"
 cellRef 812};"4235_2_SAIDAVILA"
 cellRef 1068};"4613_1_BALRAM_SADAN"
 cellRef 75};"4050_1_MTNL_TALOJE"
 cellRef 250};"4170_3_SANDEEP_APT"
 cellRef 2530};"4015_3_DRONAGIRI"
 cellRef 2355};"4245_3_SAI_PRASAD_KOPRA"
 cellRef 1661};"4210_1_AFZAL_COMPOUND"
 cellRef 765};"4116_3_MARUTI_TOWER"
 cellRef 2415};"4401_2_KALYAN_RAIL_SDCS"
 cellRef 983};"4237_1_AMAL_APARTMENT"
 cellRef 580};"4344_1_CHAMUNDA_DARSHAN"
 cellRef 2437};"4600_1_YOGESHWAR_CHS"
 cellRef 2475};"4136_2_MTNL_APMC"

Content of file2




Code:
cellRef 2530};disabled;main;0;"Trx4";
 cellRef 2530};disabled;main;0;"Trx2";
 cellRef 2355};disabled;main;12;"Trx3";outer
 cellRef 765};disabled;main;11;"Trx2";
 cellRef 580};disabled;secondary;0;"Trx5";inner
 cellRef 580};disabled;secondary;0;"Trx6";inner
 cellRef 2437};disabled;main;-1;"Trx1";
 cellRef 2437};disabled;main;-1;"Trx3";
 cellRef 2437};disabled;main;-1;"Trx2";
 cellRef 2437};disabled;main;-1;"Trx4";
 cellRef 2475};disabled;main;6;"Trx3";outer
 cellRef 2305};disabled;main;6;"Trx2";
 cellRef 2368};disabled;main;0;"Trx4";outer
 cellRef 2368};disabled;secondary;0;"Trx5";inner
 cellRef 2368};disabled;secondary;0;"Trx6";inner
 cellRef 956};disabled;secondary;4;"Trx5";inner
 cellRef 956};disabled;secondary;3;"Trx6";inner
 cellRef 932};disabled;secondary;6;"Trx5";inner
 cellRef 932};disabled;secondary;5;"Trx6";inner
 cellRef 864};disabled;secondary;4;"Trx5";inner

Both the files are semicolon separated..

First fields of both the files are common..

I want a script which will replace first field of file2 with the second field of file1 when first field of both the files matches..