Avatar of luser9999
luser9999

asked on 

Search for a string in a line and replace it with another string from another file - Shell scripting

Hi Team,

I am writing a shell script which will procedure three output files

File: Source_Lun.txt
ud1001
ud1002
ud1003
un1001
un1002

File: Dest_Lun.txt
ud2001
ud2002
ud2003
un2001
un2002

File: CloneLuns.txt

/vol/clone_vol_rtb_bed_serv1_data_03_12_2014_00_19/qa_ud1001/rtb-bed-serv1_ud1001
/vol/clone_vol_rtb_bed_serv1_data_03_12_2014_00_19/qa_ud1002/rtb-bed-serv1_ud1002
/vol/clone_vol_rtb_bed_serv1_data_03_12_2014_00_19/qa_ud1003/rtb-bed-serv1_ud1003
/vol/clone_vol_rtb_bed_serv1_data_03_12_2014_00_19/qa_un1001/rtb-bed-serv1_un1001
/vol/clone_vol_rtb_bed_serv1_data_03_12_2014_00_19/qa_un1002/rtb-bed-serv1_un1002

Now, I want to produce the forth file which should replace the last string from file CloneLuns.txt with a string value from Dest_Lun.txt

for example:

Take a first line from the file CloneLuns.txt,
"/vol/clone_vol_rtb_bed_serv1_data_03_12_2014_00_19/qa_ud1001/rtb-bed-serv1_ud1001"

Take a first line from file Dest_Lun.txt,
ud2001

I want to replace only string ( ud1001) with ud2001 from both files and write it to another file ex: modified_luns.txt

so the output should be,

"/vol/clone_vol_rtb_bed_serv1_data_03_12_2014_00_19/qa_ud1001/rtb-bed-serv1_ud2001"

and second line
and third line
and forth line so on ...

Can someone shed some light on it?

Thanks
Shankar
Shell ScriptingLinux DistributionsScripting Languages

Avatar of undefined
Last Comment
luser9999

8/22/2022 - Mon