Once I'd remembered that you don't stick $ in front of AWK variables, and that it'd be better to have them before the sentinel string...
awk '/END SENTINEL/ {print "This ["FNR"] is my new line";print;next}1' test-file
.. FNR = the line number, effectively.
So you get
forty-odd lines of blah
This [42] is my new line
END SENTINEL
more blah
Then all you have to do is remember you have to write it to a temporary file and move over the original rather than writing to the original. (A good way to delete your original!)
no subject
.. FNR = the line number, effectively.
So you get
Then all you have to do is remember you have to write it to a temporary file and move over the original rather than writing to the original. (A good way to delete your original!)