I’m trying to insert a line of text after the very last empty line in the middle of a file.
Example file:
some text
more text
blah blah blah
more blah
some more text
and even more text
The inserted text should be on line 6 for that file. I tried commands like this so far:
sed '/\n/ i some text' file
But, so far nothing has worked. Any ideas? Thanks.
A different solution with grep and awk:
awk inserts your new text after the last empty line; the index of the last empty line is selected with a proper grep which finds empty lines (or filled only with blank characters), piped into a tail to select the last one.