String replace need help ..

hi Geeks ,

I need your helps to replace /etc/fstab file entries with some new entries .. using any tool either sed or awk ..

old entry --->
new entry

oldfiler.host.box.network.com:/vol/dw188/dw188  -->
newfiler-003.host.box.lp3:/vol/oldfiler/dw188 
oldfiler.host.box.network.com:/vol/mdw018/dw205 -->
newfiler-003.host.box.lp3:/vol/oldfiler/dw205
oldfiler.host.box.network.com:/vol/mdw001/dw398 -->
newfiler-003.host.box.lp3:/vol/oldfiler/dw398
oldfiler.host.box.network.com:/vol/mdw042/dw573 -->
newfiler-003.host.box.lp3:/vol/oldfiler/dw573
oldfiler.host.box.network.com:/vol/mdw019/dw580 -->
newfiler-003.host.box.lp3:/vol/oldfiler/dw580
mainwh02.host.box.network.com:/vol/dw127/dw127  -->
newfiler-003.host.box.lp3:/vol/mainwh02/dw127
mainwh02.host.box.network.com:/vol/mdw097/dw24  -->
newfiler-003.host.box.lp3:/vol/mainwh02/dw24 
mainwh02.host.box.network.com:/vol/mdw087/dw476 -->
newfiler-003.host.box.lp3:/vol/mainwh02/dw476
mainwh02.host.box.network.com:/vol/mdw085/dw477 -->
newfiler-003.host.box.lp3:/vol/mainwh02/dw477
mainwh02.host.box.network.com:/vol/mdw072/dw493 -->
newfiler-003.host.box.lp3:/vol/mainwh02/dw493
mainwh02.host.box.network.com:/vol/mdw098/dw566 -->
newfiler-003.host.box.lp3:/vol/mainwh02/dw566
oldfiler.host.box.network.com:/vol/dw699        -->
newfiler-003.host.box.lp3:/vol/oldfiler/dw699

--lohit

something like below you want?

sed 's/oldfiler.host.box.network.com/newfiler-003.host.box.lp3/g;s/mainwh02.host.box.network.com/newfiler-003.host.box.lp3/g' filename

it will replace the oldfiler.host.box.network.com and mainwh02.host.box.network.com hostname with the new hostname newfiler-003.host.box.lp3 in the file.

You can use sed to replace string as.

sed -e 's/oldentry/newentry/g' oldfilename>newfilename

guys thanks for your quick response, but the problem here is each string contains front slash (/) and I have to replace all the lines through script in couple of servers together
..

---------- Post updated at 05:37 PM ---------- Previous update was at 04:28 PM ----------

I solved my problem this way ..

awk -F'/' '/mainwh01/ {print $NF}' old-filers | while read filr; do
  sed -i " " "/$filr/s/oldfiler.host.box.network.com:\/vol\/\(.....\)/newfiler-003.host.box.lp3:\/vol\/oldfiler\/\1/" /etc/fstab
done

awk -F'/' '/mainwh01/ {print $NF}' /tmp/old-filers | while read filr; do
  sed -i " "   "/$filr/s/mainwh02.host.box.network.com:\/vol\/\(.....\)/newfiler-003.host.box.lp3:\/vol\/mainwh02\/\1/" /etc/fstab;
done

I will really appreciate if anyone help me to optimize my logic -- thanks
--Lohit