home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sources / wanted / 3765 < prev    next >
Encoding:
Internet Message Format  |  1992-07-28  |  1.6 KB

  1. Xref: sparky comp.sources.wanted:3765 alt.sources.wanted:1287
  2. Newsgroups: comp.sources.wanted,alt.sources.wanted
  3. Path: sparky!uunet!darwin.sura.net!convex!convex!tchrist
  4. From: Tom Christiansen <tchrist@convex.COM>
  5. Subject: Re: script to center text
  6. Message-ID: <1992Jul28.104619.13095@news.eng.convex.com>
  7. Originator: tchrist@pixel.convex.com
  8. Sender: usenet@news.eng.convex.com (news access account)
  9. Nntp-Posting-Host: pixel.convex.com
  10. Reply-To: tchrist@convex.COM (Tom Christiansen)
  11. Organization: CONVEX Realtime Development, Colorado Springs, CO
  12. References: <AeRB8p600WB60JlPZc@andrew.cmu.edu>
  13. Date: Tue, 28 Jul 1992 10:46:19 GMT
  14. X-Disclaimer: This message was written by a user at CONVEX Computer
  15.               Corp. The opinions expressed are those of the user and
  16.               not necessarily those of CONVEX.
  17. Lines: 25
  18.  
  19. From the keyboard of es2j+@andrew.cmu.edu (Edward John Sabol):
  20. :Could someone post a awk, perl, or sed script which can center text. I'd
  21. :like to be able to pipe a file or region into it and get out the same
  22. :text only centered in 80 columns.
  23. :
  24. :It shouldn't be hard to do, but I don't know awk or perl very well. I
  25. :can do it in C, of course, but I want a script for ease of portability
  26. :and the smaller size. Speed needn't be an issue.
  27.  
  28. This should do it for you:
  29.  
  30.     perl -pe 'print " " x int((81 - length())/2)' 
  31.  
  32. Beware tabs: convert them with expand, or do it yourself:
  33.  
  34.     perl -pe '1 while s/\t+/" " x (length($&) * 8 - length($`) % 8)/e;
  35.           print " " x int((81 - length())/2)' 
  36.  
  37.  
  38. --tom
  39. -- 
  40.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  41.  
  42.  
  43. I want to be Robin to Bush's Batman.  --Vice President Dan Quayle
  44.