Settings

The page will reload to apply your changes.
Theme

ASCII Art Font

ASCII Art Menu

Original Usenet message from alt.ascii-art, 10 Mar 1995.
Answer: Centering Stuff

Answer: Centering Stuff

[If there's two copies of this message -- sorry...ignore this one]

> 	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...

I don't know of any way, offhand, so I threw together a little shell
script that appears to work (in UNIX at least).  Clip below (not
including) the line, call it "center" and make it executable.

And I wouldn't recommend centering pictures, unless they have two
straight margins (like a converted GIF).

Peter
-----------------------------------cut-----------------------------------
#!/bin/sh
#
# Center: centers standard input
# Something of a hack, but it works (for me at least)
# Test with something like "./this-file < this-file"
#
half=`expr ${COLUMNS-80} / 2 + 1`;
spaces="                                                                      "
while read line; do
  w1=`echo "$line" | wc -c`
  w2=`expr $half - $w1 / 2`
  if [ $w2 -gt 0 ]; then
    blank=`echo "$spaces"|cut -c-$w2`;
    echo "$blank""$line"
  else
    echo $line;
  fi;
done;

Original message headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 110f55,c4df7801762e854d
X-Google-Attributes: gid110f55,public
X-Google-Thread: fbb9d,c4df7801762e854d
X-Google-Attributes: gidfbb9d,public
X-Google-Thread: f996b,c4df7801762e854d
X-Google-Attributes: gidf996b,public
X-Google-ArrivalTime: 1995-03-09 21:00:32 PST
Path: nntp.gmd.de!news.rwth-aachen.de!news.rhrz.uni-bonn.de!news.uni-stuttgart.de!news.belwue.de!informatik.tu-muenchen.de!lrz-muenchen.de!fauern!rrze.uni-erlangen.de!rachael.franken.de!fu-berlin.de!zrz.TU-Berlin.DE!netmbx.de!unlisys!news.maz.net!news.allcon.net!watson.formel.com!flens.syd.de!sydlink.syd.de!tpki.toppoint.de!nuki.NetUSE.de!Kiel.Germany.EU.net!Hamburg.Germany.EU.net!Germany.EU.net!howland.reston.ans.net!news.sprintlink.net!news.wwa.com!not-for-mail
From: psa...@osiris.hmc.edu (Peter Samuelson)
Newsgroups: alt.ascii-art,alt.binaries.pictures.ascii,rec.arts.ascii
Subject: Answer: Centering Stuff
Date: 9 Mar 1995 23:00:32 -0600
Organization: Harvey Mudd College, Claremont CA
Lines: 35
Sender: bob...@gagme.wwa.com
Approved: bob...@wwa.com
Message-ID: <3jomdg$1a...@gagme.wwa.com>
References: <3jdmou$jr...@gagme.wwa.com>
Reply-To: Peter Samuelson <psa...@hmc.edu>
NNTP-Posting-Host: gagme.wwa.com
Xref: nntp.gmd.de alt.ascii-art:20947 rec.arts.ascii:4321
About this message. This message was posted publicly to the newsgroup alt.ascii-art in 1995 and is mirrored here unchanged as part of the Historic Archives – only email addresses are masked. The artwork and text belong to their original authors: if you copy a piece, keep the artist's initials or signature intact and credit them where you can. Are you the author? Contact us to get your posts attributed, connected to your artist profile, or removed.

Report this message

Help us keep the archive clean and accurate. Reports are reviewed by a person – nothing is changed automatically.

Help classify this post