problem in sed command

Hi,

i have a script to replace a string.

$ cat List.txt
/DIR1/DIR2/DIR3/abcdefgh
/DIR1/DIR2/DIR3/abcd
/DIR1/DIR2/DIR3/abcdefghijk
/DIR1/DIR2/DIR3/xyz

$ ind=`/DIR1/DIR2/DIR3/abcd`
$ replace=`#/DIR1/DIR2/DIR3/abcd`
$ sed "s|$find|$replace|g" List.txt>cat NewList.txt

The aim of above 3 lines are to modify the line /DIR1/DIR2/DIR3/abcd as #/DIR1/DIR2/DIR3/abcd.
but the its replacing the 3 lines as bellow

$ cat NewList.txt
#/DIR1/DIR2/DIR3/abcd
#/DIR1/DIR2/DIR3/abcdefgh
#/DIR1/DIR2/DIR3/abcdefghijk
/DIR1/DIR2/DIR3/xyz

i has to replace only one line.

help me in solving this problem.

Thanks in advance.

~Saravana..

A slight modification to your sed expression should do this.

$ sed "s|$find$|$replace|g" List.txt>cat NewList.txt

thanks yar. its working fine.

Backticks is used to set the result of a command to a variable not to assign a value to a variable, use quotes instead:

find="/DIR1/DIR2/DIR3/abcd"
replace="#/DIR1/DIR2/DIR3/abcd"

sed "s/$find/$replace/" List.txt > NewList.txt