Awking!! Printing decimal output is struck

Hi friends,

I have a small problem with AWK. I am not able to print decimal values! :confused: below is my code:

#! /bin/awk -f
awk BEGIN{printf("%d",123)}; -> This prints the integer properly.

x=111
awk BEGIN{printf("%d",x)}; -> This doesnt print! :frowning:

Please help me solve this. It is printing 0 as output.
Thanks,
Divya

Your didn't initialized the variable x within the awk instructions. Try:

 awk 'BEGIN{x=111; printf "%d", x}'

Hi,

If the value of x changes at the run time ,

u can use awk with -v option

awk -v val=$x 'BEGIN{printf("%d",val)}'

Thanks
Penchal

Thanku very much, you are helpful :slight_smile:

Thanks Penchal. :slight_smile: :slight_smile: