%.*s function in shells

Can anyone tell me now to achieve the printf %.*s functionality in shell script, (sh/ksh). I want to append x number of (same)characters at the end of a file without using normal looping.

Cheers.

qanda

Hereby the man page(sunos) for the printf command, i hope this help

thanks for the reply, but you will see from the Usage section: -

Field widths and precisions cannot be specified as *.

Even using the %.s functionality is not ideal, I would need to create a very long string, hope the required length would never exceed this and then use the . width specifier. The ideal solution would be to specify a character and a repitition count to an existing tool, sed/awk etc?

Cheers.

Take a look at the awk command:

man awk

Interesting problem. I have tested the script below and it seems to work.

#! /usr/bin/ksh

ostring=$1   # original string
char=$2      # character to append
nchar=$3     # how many chars are needed

typeset -Z${nchar} suffix=0
suffix=$(echo $suffix | sed s/0/${char}/g)
echo ${ostring}${suffix}

exit 0

thanks, but again I don't think awk supports the width specifier for strings, it does for numbers though.

cheers.

Thanks Perderabo

I like your style of thinking

I actually mistyped my original post, I need to append x characters to EACH LINE in a file, but the script you gave works great and I can modify it.

Thanks a lot.