Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!apple!voder!pyramid!prls!mips!wyse!vsi1!altnet!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.unix.questions Subject: Re: sed script to combine blank lines? Keywords: sed Message-ID: <1530@solo9.cs.vu.nl> Date: 15 Oct 88 02:42:28 GMT References: <192@vlsi.ll.mit.edu> <136@nascom.UUCP> <7372@megaron.arizona.edu> <4057@boulder.Colorado.EDU> Reply-To: maart@cs.vu.nl (Maarten Litmaath) Distribution: comp Organization: VU Informatica, Amsterdam Lines: 39 In article <4057@boulder.Colorado.EDU> wu@spot.Colorado.EDU (WU SHI-KUEI) writes: \------------------------------ cut here ------------------------------ \sed -n ' \/^[ ]*$/ { ^ \ p \: loop \ n \ /^[ ]*$/b loop \} \/[!-~][!-~]*/p' $* \------------------------------ cut here ------------------------------ At the place the caret is pointing to, a space should be added (there's only the tab)! Furthermore, formfeeds were considered white space too. This is an indication that non-printable characters (in essential places) should be avoided. One way to do it here: chars=" `echo tf | tr tf '\11\14'`" The first `p' command should be replaced by `s/.*//p', to meet what the original poster wanted. For the same reason the `/[!-~][!-~]*/p' command is doing too much: `p' suffices. \------------------------------ cut here ------------------------------ \awk ' \ BEGIN { empty = 1 } \ $0 !~ /^[ \t]+$|^$/ {print; empty = 0} \ $0 ~ /^$|^[ \t]+$/ && empty == 0 {print; empty = 1} \' $* \------------------------------ cut here ------------------------------ The `next' command of `awk' can simplify this script (see my previous posting). Why not use `/^[ \t\f]*$/' for the regular expression? Your `sed' solution (+ modifications) is the best I've seen so far. My `awk' solution is easier to program, but a lot slower indeed. -- Hippic sport: |Maarten Litmaath @ Free U Amsterdam: a contradiction in terms.|maart@cs.vu.nl, mcvax!botter!maart