Deleting (Only) First Blank Line in File
Thomas Omerzu
omerzu at quando.quantum.de
Mon Jul 2 08:15:37 AEST 1990
In article <819 at ehviea.ine.philips.nl> leo at ehviea.UUCP (Leo de Wit) writes:
>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.
NO! It is valid sed syntax.
The reason, that this does not work as supposed is different:
the pattern /^$/ matches any empty line.
On the first occurency (indicated by '1'), this emptiness is replaced
by //, i.e. nothing, and the line is p r i n t e d.
And this is the actual problem: /^$/ does n o t include the '\n',
which ist created by printing the empty line.
--
*-----------------------------------------------------------------------------*
Thomas Omerzu UUCP: ...!unido!quando!omerzu / omerzu at quando.uucp
Quantum GmbH, Bitnet: UNIDO!quando!omerzu / omerzu%quando at UNIDO(.bitnet)
Dortmund, Germany Internet: omerzu at quando.quantum.de
More information about the Comp.unix.questions
mailing list