If you're willing to use '-f' rather than '-e' then, the following sedscript does what you want: #n : noprint s/^[A-Z]/&/ t print n b noprint : print p n s/^[ ]/&/ t print b noprint Patrick Hyland.