adjusting string var to fixed length

Rob McMahon cudcv at warwick.ac.uk
Wed Jun 12 00:38:29 AEST 1991


In article <1991Jun3.181447.12656 at mnemosyne.cs.du.edu> rchattam at 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 at shark [dcv] >% set var = gronk
cudcv at shark [dcv] >% printf "x%10sx\n" $var
x     gronkx
cudcv at shark [dcv] >% printf "x%-10sx\n" $var
xgronk     x
cudcv at 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 at uk.ac.warwick             INET:   cudcv at warwick.ac.uk
Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England



More information about the Comp.unix.shell mailing list