Line 1 AAAA
Line 2 BBBB
Line 3 CCCC
Line 4 DDDD
Line 5 EEEE
Line 6 FFFF
Line 7 GGGG
Line 3 CCCC
Line 4 DDDD
Line 5 EEEE
Line 6 FFFF
Script and Comments
Script1
[ 1] 3,6!d
Comments
Any line NOT in the 3-6 range will be discarded in [1]. Then sed
will start next cycle.
At the end of each cycle, sed will print any 'survived' line and then
start next cycle; since 3rd through 6th lines are not discarded,
they will be printed.
Drawbacks: In this script, any line numbered greater
than 6 will be read into the working space, then discarded.
just wasting CPU time. We can do a little work to improve, see the next script.
Script2
[ 1] 3,6!d
[ 2] 6q
Comments
[2] will applied to line 6. sed will print line 6 then terminate.