Deleting (Only) First Blank Line in File

Leo de Wit leo at ehviea.ine.philips.nl
Sun Jul 1 23:38:52 AEST 1990


In article <1651 at fallst.UUCP> tkevans at fallst.UUCP (Tim Evans) writes:
|Can someone help me to delete the _first_ occurring blank line of a file
|(whereever it occurs) without deleting subsequent ones?
|
|You'd think the following would work, but it doesn't:
|
|	sed 's/^$//1' foo > newfoo

Sure. It isn't valid sed syntax.

|
|Solutions other than those using 'perl' are preferred.

Here's a quick and dirty one with sed:

sed -n -e '
    /^$/{
        : back
        n
        p
        b back
    }
    p' foo >newfoo

All lines before the first empty line are printed by the last 'p' command.
Then, at the first empty line, each next line is read in and printed.

    Leo.



More information about the Comp.unix.questions mailing list