How to insert a line into a file using sed before a pattern and after a line number? And how to use the same in shell script?
This inserts a line before
I assume you want to insert the line before a pattern only if the current line number is greater than some value (i.e. if the pattern occurs before the line number, do nothing)
If you're not tied to sed:
awk -v lineno=$line -v patt="$pattern" -v text="$line_to_insert" '
NR > lineno && $0 ~ patt {print text}
{print}
' input > output