printf: placing a percent sign

Hi!

I already solved this little problem of mine with regards to having

zero as my denominator when I'm dividing numbers(the reason why I change

the subject). One last question with regards to this posting.

My last question is on how to insert a percentage sign after a floating

point number when using "printf".

My script contains this:

printf "%1s %5s $%5s %7.2f %5s\n",$1, $2, $3, calc, $5

I tried doing the following but still I can't show the percentage using

printf.

printf "%1s %5s $%5s %7.2f% %5s\n",$1, $2, $3, calc, $5

0.39%5s

printf "%1s %5s $%5s %7.2f"%" %5s\n",$1, $2, $3, calc, $5

awk: division by zero in mod

input record number 1, file 41008.sec

source line number 9

printf "%1s %5s $%5s %7.2f\% %5s\n",$1, $2, $3, calc, $5

0.39\%5s

printf "%1s %5s $%5s %7.2f"\%" %5s\n",$1, $2, $3, calc, $5

awk: syntax error at source line 9

context is .....................................

.....................................................

awk: illegal statement at source line 9

printf "%1s %5s $%5s %7.2f\"%" %5s\n",$1, $2, $3, calc, $5

awk: syntax error at source line 9

context is .....................................

.................................................

awk: illegal statement at source line 9

The only way I can make the percent (%) appear at the end of the

floating

point number is by using:

awk '

{

print $1"\t", $2"\t", $3"\t", calc"%""\t", $5"\t"}' infile > outfile

Does anybody knows how to place a percent sign (%) after a floating

point number using printf?

What other escape character did I miss?

Any suggestions on how to do this? Just send me an email or

you can answer me by posting in

this group.

Thank you very much.

Albert

**********************************************************************************

Quote:

> >Hi guys,

> > I'm really new to awk and I need to do some "simple"arithmetic

> >calculations using awk.

> >I know this is a very easy calculation but just can't figure it out on

> >my own. I need some help.

> >Whenever my "infile" contains a Zero (0) value in one of its field and

> >it becomes a denominator

> >in my simple arithmetic calculation, I always got this message:

> >1 2 $3 awk: division by zero

> >input record number 1, file 1.1

> Correct - that's what most programming language will do ;-)

> What you want to do is put the awk program in a file (to make it

> easier to manage/control) and build in some specific code to check for it

> The file prog.awk will contain

> >awk '

> {

> calc=0

> if ($4+0 > 0) calc= ((($3-(($2+$6)/$4))+$1)/2)*100

> print $1"\t", $2"\t", "$"$3"\t", "\t", calc,"\t", $5"\t"}

> And then type

> awk -f prog.awk infile ....

> As regards formatting, you may find it easier to use the printf statement

> heres an example

> printf "%10s %10s $%-10s %7.2f %10s\n",$1, $2, $3, calc, $5

> Also you may want to use the INT function to avoid rounding errors

> Hope this helps

> Mark

> ps There may be syntax errors - please check

> --

> Mark Katz

> ISPC, London - Innovation in data-delivery tools

> Tel: (44) 181-455 4665, Fax (44) 181-458 9554

> ** See our website at http://www.*-*-*.com/ **

--

Just me,

Albert