Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!tellab5!vpnet!dattier From: dattier@vpnet.chi.il.us (David W. Tamkin) Newsgroups: comp.unix.shell Subject: Re: deleting some empty lines with sed Message-ID: <1991May02.005009.27947@vpnet.chi.il.us> Date: 2 May 91 00:50:09 GMT References: <1991Apr27.143519.26256@daimi.aau.dk> <281DB41B.9E6@marob.uucp> Organization: VPnet Public Access Unix, Villa Park, Illinois 60181-2206 Lines: 69 daveh@marob.uucp (Dave Hammond) wrote in <281DB41B.9E6@marob.uucp>: | Perhaps I'm oversimplifying the problem, but wouldn't | tr -s '\012' | squeeze multiple, consecutive newlines to a single newline? Yes, but that isn't what we want. The identical misunderstanding came up when someone asked the same question a few months ago, and many skimmers made equivalent suggestions [such as sed '/^$/d'], which don't answer the question at hand. Compressing all consecutive newlines to a single newline (1) assumes that there are no non-empty blank lines (containing spaces and tabs but no printing text) and (2) removes all empty lines. By leaving only one newline character between two consecutive lines that have text, you're removing all blank lines from the document. Since that may not be obvious, let me illustrate. Here is some text. I'll represent newline characters with "^J". ^J ^J Hi there!^J ^J ^J It's nice to see you again.^J How was your trip?^J ^J ^J ^J David^J ^J The goal is to get this: Hi there!^J ^J It's nice to see you again.^J How was your trip?^J ^J David^J All leading newlines are stripped, two or more trailing newlines are compressed to one, and any string of three or more intermediate newlines is reduced to two. That's none at the top, two anywhere in the middle, and one at the end. If we run it through tr -s '\012' we get one newline no matter where, with this result: ^J Hi there!^J It's nice to see you again.^J How was your trip?^J David^J The paragraphing is lost and one blank line at the top is still there. The question is how to squeeze all consecutive blank lines to a single blank line (which is what cat -s does on a BSD system). Removing all blank lines and getting solid blocks of text is not the answer! David Tamkin PO Box 7002 Des Plaines IL 60018-7002 dattier@vpnet.chi.il.us GEnie:D.W.TAMKIN CIS:73720,1570 MCIMail:426-1818 708 518 6769 312 693 0591 "Parker Lewis Can't Lose" mailing list: flamingo-request@esd.sgi.com (relay) flamingo-request@ddsw1.mcs.com (digest)