sed to delete selected line from file

Ultimate goal is to delete lines from before and after a block of lines in a given file. First attempt was something like this:

sed -e '1,/STARTUP/ d' inputfile.txt     > outputfile.txt

but that deleted everything down to and including the line with STARTUP. I need to delete everything before that line.

next attempt was

 
lines=`grep -m 1 -n "STARTUP" inputfile.txt  |  awk -F: '{print $1}'`
fline=`expr $lines + 1`
sed -e '1,${fline} d'   inputfile.txt  > outputfile.txt

But that appears to create 'fline' with spaces before and after the returned line number, which then causes sed to choke:

estevens:work$ cat fixit
set -x
lines=`grep -m 1 -n "STARTUP" inputfile.txt | awk -F: '{print $1}'`
fline=`expr $lines + 1`
echo ":" $fline ":"
sed -e '1,${fline} d' inputfile.txt > outputfile.txt

estevens:work$ ./fixit
+++ grep -m 1 -n STARTUP inputfile.txt
+++ awk -F: '{print $1}'
++ lines=51
+++ expr 51 + 1
++ fline=52
++ echo : 52 :
: 52 :
++ sed -e '1,${fline} d' inputfile.txt
sed: -e expression #1, char 5: unknown command: `f'

estevens:work$

Here is an example how you can delete everything before pattern: STARTUP

awk '/STARTUP/{i++}i' inputfile.txt

That works for the specific case (still trying to get my head around HOW :)) but I also need to delete everything *following* another string. I only presented the once case because with the approach I was taking, when I had a fix I could use the same technique on the other end.

So I guess I have two goals:
1) how to delete all lines prior to a given line, and all lines following a given line
2) understand why my own code isn't working, so that I can increase my generalize knowledge.

awk '/STARTUP/{i++}/END/{print;i=0}i' file

Please see the corrections:

lines=`grep -m 1 -n "STARTUP" inputfile.txt | awk -F: '{print $1}'`
fline=`expr $lines - 1`
echo ":" $fline ":"
sed -e "1,${fline}d" inputfile.txt

A little more tweaking, but that did it. Can you explain why the change from single- to double-quote to enclose the sed commands? ( I had to add back the space separating the 'd' (delete) from the range, but that was no big deal).

Since you are using the variable: ${fline} inside sed you have to use double-quotes to expand this variable.

Single-quotes prevents variable expansion.

sed -i '/STARTUP/,$!d' file