#!/usr/bin/sed -nf # delete all blanks /./!d # get here: so there is a non empty :x # print it p # get next n # got chars? print it again, etc... /./bx # no, don't have chars: another empty line :z # get next n # also empty? then ignore it, and get next... this will remove ALL empty # lines, if we get to end, sed script will finish on n(ext) command # so no trailing empty lines are written /./!bz # all empty lines were deleted/ignored, but we have a non empty, as # what we want to do is to squeeze, insert a blank line artificially i\ bx