Inserting Blank Line into File (sed/awk/?)

Tom Christiansen tchrist at convex.COM
Sat Mar 16 05:06:07 AEST 1991


>From the keyboard of tkevans at oss670.UUCP (Tim Evans):
:I would like to be able to insert blank lines at regular intervals
:in a structured file.  Specifically, I want to place a blank line after
:every third line in my input file.  Every third line in the input file
:begins with a specific character string.

I hate doing multi-line things in sed: it's such a pain.

If you cna really do this just by putting an extra newline
after each third line rather than keying off /^Name:/, just
use one of these:

    awk '{ print; if (!(NR % 3)) print "\n" }'

    perl -pe 's/$/\n/ unless $. % 3'

    perl -pe '$. % 3 || s/$/\n/'

--tom



More information about the Comp.unix.questions mailing list