POSIX.2 has the printf command in /usr/bin ....
% printf "%20s\n" hello
hello
but I'm not sure how many systems have it. (solaris, osx and linux do)
Tim
On Mon, 5 Sep 2005, Malcolm J. Currie wrote:
> One gem not in the C-Shell Cookbook is how to right justify some text or
> put N spaces before a word for aligned output. Simple stuff is
> straightforward.
>
> set output = " Frequency"
> echo $output ! Loses the leading blanks.
> echo "$output" ! Retains the leading blanks.
>
> Now I have a label not of fixed length---it comes from inquiring an NDF
> attribute---that I want right justified in some output in order to align
> with other commentary. I've derived the number of preceding blanks
> ($nb) and need to prepend the blanks. [There's probably a better way to
> write a certain number of blanks followed by the fields from the second
> element, but I didn't have any awk documentation at home when I wrote
> this code.]
>
> set lab = "Frequency"
> set rjl = `echo $nb $lab | \
> awk '{op=" "; for (i=1; i<$1; i++) op = op" "; split($0,a," "); for (i=2; i<=NF; ++i) op=op" "a[i]; print op}'`
> echo "$rjl"
>
> rjl has lost the leading blanks.
>
> If I just have
> echo $nb $lab | \
> awk '{op=" "; for (i=1; i<$1; i++) op = op" "; split($0,a," "); for (i=2; i<=NF; ++i) op=op" "a[i]; print op}'
>
> the output to stdout has the spaces. Does anyone have a robust method
> of retaining the leading spaces please?
>
> Another reason for using perl?
>
> Malcolm
>
--
Tim Jenness
JAC software
http://www.jach.hawaii.edu/~timj
|