Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!ukc!warwick!cudcv From: cudcv@warwick.ac.uk (Rob McMahon) Newsgroups: comp.unix.shell Subject: Re: adjusting string var to fixed length Message-ID: <}07_7M$@warwick.ac.uk> Date: 11 Jun 91 14:38:29 GMT References: <1991Jun3.181447.12656@mnemosyne.cs.du.edu> Sender: news@warwick.ac.uk (Network news) Organization: Computing Services, Warwick University, UK Lines: 28 Nntp-Posting-Host: shark In article <1991Jun3.181447.12656@mnemosyne.cs.du.edu> rchattam@isis.cs.du.edu (King Chattam) writes: >I have a shell var (length 0 to 10), which I want always to be output to a >file as fixed length 10. Strange no-one has mentioned Chris Torek's `printf': cudcv@shark [dcv] >% set var = gronk cudcv@shark [dcv] >% printf "x%10sx\n" $var x gronkx cudcv@shark [dcv] >% printf "x%-10sx\n" $var xgronk x cudcv@shark [dcv] >% /* * printf - duplicate the C library routine of the same name, but from * the shell command level. * * This version by Chris Torek, based on an earlier version by Fred Blonder. */ Cheers, Rob -- UUCP: ...!mcsun!ukc!warwick!cudcv PHONE: +44 203 523037 JANET: cudcv@uk.ac.warwick INET: cudcv@warwick.ac.uk Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England