don_crissti and terdon did all the hard work; I saw this question and wanted to suggest using a shell function to further reduce typing / memorization, and perhaps add some flexibility. While typing it up, I've also taken the liberty of tightening down the regular expression some, to avoid false positives.
Here's the shell function:
function step () (
STEPS=./steps.txt
start=$1
stop=$((start+1))
sed -n "/^Step $start:/,/^Step $stop:/ { /^Step $stop:/ !p }" $STEPS
)
You're obviously free to name it whatever you like; step seemed intuitive to me based on the wording of the instruction file. Adjust the STEPS variable to be the full path to the actual instruction file; that way, you don't have to remember -- or type! -- the path to that file at the command-line. I made the function use a subshell -- parens around the body instead of braces -- because I didn't want to pollute your shell's namespace with the STEPS, start, and stop variables. If creating a subshell is more bothersome than three new variables, feel free to change the second set of parenthesis over to curly braces.
I did two basic things to the regular expression that don & terdon used:
- Forced the match to start at the beginning of the line, and
- required it to contain the word "Step" followed by the number, followed by a colon.
I did both of those things because I can imagine the instruction file potentially containing numbers inside the commands to execute and so causing the simpler regex to falsely match.
Here's the "devil's advocate" steps.txt file I was using:
Step 1: one
commands to execute
Step 2: two
commands to execute
commands to execute
Step 3: three
commands to execute skip to Step 7
Step 4: four
commands to execute not step 5
commands to execute
commands to execute
commands to execute
Step 5: five
commands to execute
commands to execute
commands to execute skip to Step 6:
commands to execute
Step 6: six
commands to execute
Step 7: seven
commands to execute
Step 8: eight
commands to execute
Step 9: nine
commands to execute
Step 10: ten
commands to execute
Step 11: eleven
commands to execute
Step 12: something
commands to execute
commands to execute
Step 13: something else
commands to execute
... and the results of a test harness (the output from step 14 is empty):
$ for step in $(seq 1 14); do step $step; echo; done
Step 1: one
commands to execute
Step 2: two
commands to execute
commands to execute
Step 3: three
commands to execute skip to Step 7
Step 4: four
commands to execute not step 5
commands to execute
commands to execute
commands to execute
Step 5: five
commands to execute
commands to execute
commands to execute skip to Step 6:
commands to execute
Step 6: six
commands to execute
Step 7: seven
commands to execute
Step 8: eight
commands to execute
Step 9: nine
commands to execute
Step 10: ten
commands to execute
Step 11: eleven
commands to execute
Step 12: something
commands to execute
commands to execute
Step 13: something else
commands to execute