lovingboth: (0)
Ian ([personal profile] lovingboth) wrote 2009-05-15 08:57 pm (UTC)

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!)

Post a comment in response:

(will be screened)
(will be screened if not validated)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org