Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!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: <1991Apr30.211100.11102@vpnet.chi.il.us> Date: 30 Apr 91 21:11:00 GMT References: <1991Apr27.143519.26256@daimi.aau.dk> <1991Apr27.211212.18855@convex.com> <1991Apr29.150244.4378@ssd.kodak.com> Organization: VPnet Public Access Unix, Villa Park, Illinois 60181-2206 Lines: 51 weimer@ssd.kodak.com (Gary Weimer) wrote in <1991Apr29.150244.4378@ssd.kodak.com>: | In article <1991Apr27.211212.18855@convex.com>, Tom Christiansen | writes: | |> From the keyboard of datpete@daimi.aau.dk (Peter Andersen): | |> :I have some source-files that I produce documentation from. | |> :If two or more blank lines appear, I want to remove all but | |> :one of these. | |> :I have tried the following sed script [script deleted] | |> :but it didn't work. | |> You need to set up a look with labels and branches. I see that as I type | |> this another poster has given you a sed solution, so I won't post my | |> crufty version of the same. Well, I haven't seen those sed solutions; they aren't here yet or they're already gone. | Wouldn't 'cat -s' be easier? I know, it's not near as exciting, but... cat -s on a BSD system, yes, but in System V cat -s does something completely different (it _s_uppresses error messages if input files are nonexistent or unreadable or if the output file cannot be written). We went around this subject on comp.editors several months ago. The best sed soluation was posted by someone whom I cannot name (because at the same time a person with a very similar name posted one that didn't work, and I can never remember which name belonged to which person. The sed script boiled down to three lines (the ^I represents a tab): s/[ ^I]*$// /^$/N /[!-~]/!D If the input begins with one or more blank lines, a single empty line will be preserved at the start of the output. To get rid of that as well, add /./,$ !d after the first line. 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)