output:
if i search for starting with 9999 and dbc10 then it should print from starting 9999 until next occurance of 9999.
9999~cbuc~101~109~oiuxczcz~1000198230001~1609~dbc10
123~a~sdklfjl~sldoi~dbc10~~ksjdfnkjsdf~123456
124~g~sdklfjl~slsdfsdfsdfsdfdoi~~~~~~~~ksjdfnkjsdf~345
126~wera~sdklfjl~sldoi~~~ksjdfnkjsdf~9999
1223~awer~swerwerdklfjl~sldoi~~~ksjdfnkjsf~1da2345
Because the awk script is in single quotes in your code, the $temp variable does not get expanded. You would need to use double quotes, but that poses other kinds of issues. A good way is to use the -v variable= method:
Try:
while read samp
do
awk -v temp="T1$samp" '/^9999|~/{p=0} $0~temp{p=1}p' file
done < input.txt
Also note the the / .. / is a constant match in which you cannot use variables. Therefore you need to use $0~var instead.