How to use a shell variable on sed command?

Hie everyone

i have a complex sed command line which work fine for a static value given
example

sed -n '/SQL ID\:\ 1111111111111/!b;:a;/\*\*\*\*\*\*\*\*\*\*\*\*/!{$!{N;ba}};{/*/p}' ./MyInputFile.txt

what i want is something like that

sed -n '/SQL ID\:\ ${vSQL_ID}/!b;:a;/\*\*\*\*\*\*\*\*\*\*\*\*/!{$!{N;ba}};{/*/p}' ./MyInputFile.txt

i know that with single quote the variable will not be interpreted and it will be shown as a string character.

So the question is what is the alternative with this sed command to pass the variable ?

thanks for your help

Hello ade05fr,

Welcome to forums, could you please try following and let me know if this helps you.

sed -n '/SQL ID\:\ '"${vSQL_ID}"'/!b;:a;/\*\*\*\*\*\*\*\*\*\*\*\*/!{$!{N;ba}};{/*/p}'  Input_file
OR
sed -n "/SQL ID\:\ ${vSQL_ID}/!b;:a;/\*\*\*\*\*\*\*\*\*\*\*\*/!{$!{N;ba}};{/*/p}"  Input_file

As sample(test) Input_file was not provided so couldn't test it.

Thanks,
R. Singh

thanks it works for one of these solutions

sed -n "/SQL ID\:\ ${vSQL_ID}/!b;:a;/\*\*\*\*\*\*\*\*\*\*\*\*/!{$!{N;ba}};{/*/p}"  Input_file
-ksh: syntax error: `}' unexpected
AND
sed -n '/SQL ID\:\ '"${vSQL_ID}"'/!b;:a;/\*\*\*\*\*\*\*\*\*\*\*\*/!{$!{N;ba}};{/*/p}'  Input_file
==> result OK !!