home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / question / 9311 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  1.7 KB

  1. Path: sparky!uunet!mcsun!fuug!demos!kiae!glas!demos!netlabs.com!lwall
  2. From: lwall@netlabs.com
  3. Newsgroups: comp.unix.questions
  4. Date: 18 Jul 92 00:29 MDT
  5. Subject: Re: stripping trailing blank lines
  6. Sender: Notesfile to Usenet Gateway <notes@glas.apc.org>
  7. Message-ID: <1992Jul17.202902.20496@netlabs.c>
  8. References: <1992Jul16.065321.334861@zeus.cal>
  9. Nf-ID: #R:1992Jul16.065321.334861@zeus.cal:-1715338178:1992Jul17.202902.20496@netlabs.c:1613040256:001:1184
  10. Nf-From: netlabs.com!lwall    Jul 18 00:29:00 1992
  11. Lines: 56
  12.  
  13.  
  14. In article <1992Jul16.133348.21297@news.eng.convex.com> tchrist@convex.COM (Tom Christiansen) writes:
  15. : From the keyboard of ctuel@zeus.calpoly.edu (Cliff Tuel):
  16. : :I'm looking for a quick and dirty way to strip trailing blank lines 
  17. : :from a file.  I know I can use a script based on "tail -1" and a
  18. : :temporary file, but is there an easier way to do it with sed, awk,
  19. : :perl, etc.?
  20. : :
  21. : :------ Sample input ------
  22. : :this line has text
  23. : :so does this one
  24. : :the next line is blank
  25. : :
  26. : :the previous line is blank
  27. : :the next two lines are blank
  28. : :
  29. : :
  30. : :------ Sample output -------
  31. : :this line has text
  32. : :so does this one
  33. : :the next line is blank
  34. : :
  35. : :the previous line is blank
  36. : :the next two lines are blank
  37. : :----------------------------
  38. : I'm sure someone else will provide a sed solution and maybe even and awk
  39. : one, and if Larry Wall isn't too busy, he'll give us one in nroff.  
  40.  
  41. Whaddya mean, "too busy"?  It's not as if it takes all day.
  42.  
  43. #!/bin/sh
  44. (
  45.     cat <<-'END'
  46.     .de TR
  47.     'di
  48.     .pl 1000v
  49.     .aa
  50.     .ST
  51.     ..
  52.     .de ST
  53.     .pl 1n
  54.     'di aa
  55.     .nr .i 0
  56.     .it 1 TR
  57.     ..
  58.     .nf
  59.     .ST
  60.     END
  61.     cat ${1-"$@"}
  62. ) | nroff
  63.  
  64. Seems perfectly straightforward to me...  :-)
  65.  
  66. Larry
  67.  
  68.