Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!zardoz.cpd.com!spsd!dg-rtp!wgate!lanzo From: lanzo@wgate.UUCP (Mark Lanzo) Newsgroups: comp.unix.shell Subject: Re: adjusting string var to fixed length Message-ID: <190@atesysv.UUCP> Date: 5 Jun 91 20:29:20 GMT References: <1991Jun3.181447.12656@mnemosyne.cs.du.edu> Reply-To: lanzo@atesysv.UUCP (Mark Lanzo) Organization: Wandel & Goltermann Technologies, Inc. Lines: 33 In a prior article rchattam@isis.cs.du.edu (King Chattam) wrote: Netters, I have a shell var (length 0 to 10), which I want always to be output to a file as fixed length 10. I tried sed, awk etc to adjust the string length to 10, but did not work. Could someone please tell me how blanks can be appended to string vars to make it fixed length? You need to include more information in your posts. Remember that not everyone is working on the same type of system that you are. What shell are you using? If you are using "ksh", then it is very easy to do what you want: typeset -L10 shell_variable for example: myname=Mark typeset -L10 myname echo "XX${myname}XX" should produce XXMark XX If you are using "sh" or "csh", then it's going to be harder as there isn't anything built-in to the shell to do it for you. "Expr" or "sed" or "awk" could be used, in a clumsy fashion. For example, using expr with csh: set name=Mark set padded_name = "`expr substr $name:q'XXXXXXXXXX' 1 10`" # Use 10 spaces where I have shown the X's above.