Tuesday, February 27, 2007

Removing leading 0's


Suppose Number = 0000000231
Output Required = 231
i.e. we have to remove the leading zero's from the number.

$ echo "0000000231" | awk '{printf "%d\n",$1}'
231

$ echo "0000000231" | awk '{print $1 + 0}'
231

$ echo "0000000231" | sed 's/^0*//g'
231

1 comment:

Srimay said...

Looks like u r fond of "SED" and "AWK". All your posts are of real help. Thanks buddy....

© Jadu Saikia www.UNIXCL.com