home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!fuug!demos!kiae!glas!demos!netlabs.com!lwall
- From: lwall@netlabs.com
- Newsgroups: comp.unix.questions
- Date: 18 Jul 92 00:29 MDT
- Subject: Re: stripping trailing blank lines
- Sender: Notesfile to Usenet Gateway <notes@glas.apc.org>
- Message-ID: <1992Jul17.202902.20496@netlabs.c>
- References: <1992Jul16.065321.334861@zeus.cal>
- Nf-ID: #R:1992Jul16.065321.334861@zeus.cal:-1715338178:1992Jul17.202902.20496@netlabs.c:1613040256:001:1184
- Nf-From: netlabs.com!lwall Jul 18 00:29:00 1992
- Lines: 56
-
-
- In article <1992Jul16.133348.21297@news.eng.convex.com> tchrist@convex.COM (Tom Christiansen) writes:
- : From the keyboard of ctuel@zeus.calpoly.edu (Cliff Tuel):
- : :I'm looking for a quick and dirty way to strip trailing blank lines
- : :from a file. I know I can use a script based on "tail -1" and a
- : :temporary file, but is there an easier way to do it with sed, awk,
- : :perl, etc.?
- : :
- : :------ Sample input ------
- : :this line has text
- : :so does this one
- : :the next line is blank
- : :
- : :the previous line is blank
- : :the next two lines are blank
- : :
- : :
- : :------ Sample output -------
- : :this line has text
- : :so does this one
- : :the next line is blank
- : :
- : :the previous line is blank
- : :the next two lines are blank
- : :----------------------------
- :
- : I'm sure someone else will provide a sed solution and maybe even and awk
- : one, and if Larry Wall isn't too busy, he'll give us one in nroff.
-
- Whaddya mean, "too busy"? It's not as if it takes all day.
-
- #!/bin/sh
- (
- cat <<-'END'
- .de TR
- 'di
- .pl 1000v
- .aa
- .ST
- ..
- .de ST
- .pl 1n
- 'di aa
- .nr .i 0
- .it 1 TR
- ..
- .nf
- .ST
- END
- cat ${1-"$@"}
- ) | nroff
-
- Seems perfectly straightforward to me... :-)
-
- Larry
-
-