Q:

SED command is not working

I am facing some problem in below command
INPUT_FILE_NAME_PATH="/app/csa/sumit/xyz.out"

sed -i "s/^$InputFile=.*/$InputFile='${INPUT_FILE_NAME_PATH}'/g" dashboard.prf

ERROR : sed: -e expression #1, char 36: unknown option to `s'

When i am using the value of INPUT_FILE_NAME_PATH without using "/" then it is working fine..but when i use "/" in the value of variable INPUT_FILE_NAME_PATH then it is giving error. I know that problem with "/" character. But can any one help me to resolve this problem.
Any help is appreciated. 

A:

You can use the @ character instead of / for the separator, so your code would look like:
INPUT_FILE_NAME_PATH="/app/csa/sumit/xyz.out"

sed -i 's@^$InputFile=.*@$InputFile='${INPUT_FILE_NAME_PATH}'@g' dashboard.prf

You can use sed -n and add a trailing p to test regular expressions without modifying the file in question and only displaying if it matches, so for example:
sed -n 's@^$InputFile=.*@$InputFile='${INPUT_FILE_NAME_PATH}'@gp' dashboard.prf

and it will only print if it matches. It is not a good idea to combine -n and -i, as you end up with a very small file :(

