X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f996b,c4df7801762e854d X-Google-Attributes: gidf996b,public X-Google-Thread: fbb9d,c4df7801762e854d X-Google-Attributes: gidfbb9d,public X-Google-Thread: 110f55,c4df7801762e854d X-Google-Attributes: gid110f55,public X-Google-ArrivalTime: 1995-03-08 05:19:26 PST Path: bga.com!news.sprintlink.net!news.wwa.com!not-for-mail From: Tony Nugent Newsgroups: alt.ascii-art,alt.binaries.pictures.ascii,rec.arts.ascii Subject: Answer: Centering Stuff Date: 7 Mar 1995 02:21:17 -0600 Organization: Griffith University Brisbane Queensland Australia Lines: 108 Sender: boba@gagme.wwa.com Approved: boba@wwa.com Message-ID: <3jh51t$1ef@gagme.wwa.com> References: <3jdmou$jrf@gagme.wwa.com> Reply-To: T.Nugent@sct.gu.edu.au NNTP-Posting-Host: gagme.wwa.com Xref: bga.com alt.ascii-art:19544 alt.binaries.pictures.ascii:2170 rec.arts.ascii:4245 Brad writes: > Does anybody have a script that centers text or pictures or whatever? >I know this is only a really simple tr command, but I can't figure it out >right now. :) Thanks... tr(1) is used to _translate_ characters... I don't think you can use it to do text centering. Ok, I have *two* solutions... This awk script will center text according to the length of *each* input line: ========8<----cut-all-above-this-line-and-keep-all-below------- #!/usr/bin/awk -f # # center # # Centers all input text on an 80-column line according to the # length of each input line. # # Tony Nugent ** T.Nugent@sct.gu.edu.au ** tnugent@gucis.cit.gu.edu.au # { pad="" if ( length < 78 ) { le = ( 80-length ) / 2 for ( i=0 ; i le ) { le = length } line[numlines++] = $0 } END { pad="" if ( le < 78 ) { le = ( 80-le ) / 2 for ( i=0 ; i<=le ; i++ ) { pad=pad" " }; } for ( i=0; i