divzz
1
Hi friends,
I have a small problem with AWK. I am not able to print decimal values! 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!
Please help me solve this. It is printing 0 as output.
Thanks,
Divya
ripat
2
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
divzz
4
Thanku very much, you are helpful