You can specify a range of lines to operate on. For example, to operate on all lines, (which is of course the default):
sed -e \"1,$ s/a/b/\"
In a more general sense, this issue requires you to edit a stream by specifying a range with one of the range limits being an offset from the end-of-file. The following example shows how to do this. In this example I am printing out all the lines of a file, beginning with the 5th line from the last line, and ending with the last line. In your case, you can set OFFSET = -1instead of OFFSET = -5.
(( OFFSET = -5 )); (( N1 = $(cat pgen.c | wc -l) + OFFSET )); sed -n "$N1,\$p" thefile
This command can be entered in one line.