Issue in using variable within sed command

Hi All,

I am trying to use a variable within the sed command but I am not able to get the output.

When I am using the following command (without variable) its working fine:

sed -n '/2011\/12\/10 18:11:11./,$p' < Log.txt > Delta_Log.txt

But when I am putting the value 2011\/12\/10 18:11:11. in variable date_str and then use the variable, there is no output.

Have tried the following syntax's:

sed -n '/$date_str/,$p' < Log.txt > Delta_Log.txt
sed -n '/"$date_str"/,$p' < Log.txt > Delta_Log.txt

Single quotes prevent the shell to expand the variables, try it with double quotes:

sed -n "/$date_str/,$p" < Log.txt > Delta_Log.txt

Hi Franklin,

Tried it with double quotes but getting the following error message:

sed: Function /2011\/12\/10 18:11:11./, cannot be parsed

When you are weak-quoting (double-quotes) for expansion/evaluation by the shell, make sure that the $ (last line for sed) is not evaluated by escaping it.

sed -n "/${date_str}/,\$p" <filename>

Thanks a lot!!!

Now it works