Replacing Port number Using Sed

Hi
Im trying to replace http port value.However for some reason its not working.Can you guys take a look and hit me with suggestions please.Your help is much appreciated.

echo "Enter Value"
read ans
sed -i "s/http-port = 80 /http-port = $ans/g" demo

Note:demo is the filename

Thanks guys
CK

you getting any error??

Im not getting errors however its not working meaning its taking the value however it is not changing the value..

can you post the input data line from file demo..

Here is what im getting

host$ cat demo
http-port = 80

host$ ./test2
enter value
81

host$ cat demo
http-port = 80

Filename:test2 has the code I posted earlier and it should change the http-port value in Filename:demo.

The value in the file:demo should be 81 after executing test2, which is not happening..

Thanks
CK

Hi.

Based on your original sed:

sed "s/http-port = 80 /http-port = $ans/g" demo

all I can see that is wrong is a space before the / in the substitution part of your sed expression:

i.e. should be

sed "s/http-port = 80/http-port = $ans/g" demo
$ cat Test
ans=81
sed "s/http-port = 80 /http-port = $ans/g" demo
$ ./Test
http-port = 80

$ cat Test
ans=81
sed "s/http-port = 80/http-port = $ans/g" demo
$ ./Test
http-port = 81

Yep, you are right.thank you sir, its working now.