You can use sed = function to write the line number on a line by itself and sed d function to delete the matching pattern. So :
}' [input file]
will output :
Assuming you don't have numbers on a line by themselves in the original file you can chain a second sed command to add the ‘echo print’ for those lines, something like :
sed 's/^(\d+)$/echo print \1/'
although the exact syntax may change depending on your system (\d not always being available and so on...)
sed is probably not the simplest tool to do that.