#!/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... /./ b x # 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 /./ !b z # 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\ b x ### colorized by sedsed, a debugger and code formatter for sed scripts ### original script: http://sed.sf.net/grabbag/scripts/cat-s.sed