How to insert a line using sed before a pattern and after a line number?
You can either write a sed script file and use:
sed -f sed.script file1 ...
Or you can use (multiple) -e 'command'
options:
sed -e '/SysAdmin/i\
Linux Scripting' -e '1,$s/A/a/' file1 ...
If you want to append something after a line, then:
sed -e '234a\
Text to insert after line 234' file1 ...
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