Core iTOps Tube

Wednesday, 9 May 2012

SED/AWK maybe PERL in a WHILE loop

Hi,



I have a file containing numerous string values, for example:




Code:


AMFU8849636

CCLU7120334

GESU5784065

TEMU3070096


I have a second file with multiple records, such as the one below that I would like to manipulate based on the strings from the first file:




Code:


CATOS2EDI DSTOW    ABC            EGLV          20120426141639  4180000000161D

CONTAINER EGLVAMFU8849636F31305  LBG4506I540916 EMCFHY8260           

TRACE    END

CATOS2EDI DSTOW    ABC            EGLV          20120426141639  4180000000161D

CONTAINER EGLVAMFU8849636F31305  LBG4506I540916 EMCFHY8260           

TRACE    END

CATOS2EDI DSTOW    ABC            EGLV          20120426141639  4180000000161D

CONTAINER EGLVAMFU8849636F31305  LBG4506I540916 EMCFHY8260           

TRACE    END


I would like to take each value from the first file and search for it in the second file. If found, I would like to change the 'EGLV' to 'CHNJ'.



For example:




Code:


while read line

do

    sed s/EGLV${line}/CHNJ${line}/g second_file

done < first_file


Just not getting the output that I would like:



Desired output example:




Code:


CATOS2EDI DSTOW    ABC            EGLV          20120426141639  4180000000161D

CONTAINER CHNJAMFU8849636F31305  LBG4506I540916 EMCFHY8260           

TRACE    END

CATOS2EDI DSTOW    ABC            EGLV          20120426141639  4180000000161D

CONTAINER EGLVAMFU1234567F31305  LBG4506I540916 EMCFHY8260           

TRACE    END

CATOS2EDI DSTOW    ABC            EGLV          20120426141639  4180000000161D

CONTAINER EGLVAMFU8910112F31305  LBG4506I540916 EMCFHY8260           

TRACE    END


As you can see, only the first CONTAINER segment line matched up and was changed.



Any advice?



Chris




No comments:

Post a Comment