As Lev Levitsky noted, this is not possible with one call to sed, because the line number is sent directly to the standard version.
You may have sed write a sed script for you and do the replacement in two passes:
input_file
a b c d e ### ### ### a b ### c d e ###
Find the lines containing the pattern:
sed -n '/###/=' infile
Output:
6 7 8 11 15
A pipe that in sed-script writes a new sed-script:
sed 's:.*:&s/###/&/:'
Output:
6s/###/6/ 7s/###/7/ 8s/###/8/ 11s/###/11/ 15s/###/15/
Execute:
sed -n '/###/=' infile | sed 's:.*:&s/^/& \&/:' | sed -f - infile
Output:
a b c d e 6 7 8 a b 11 c d e 15
source share