String operations

Hi All,

can you tell me how to drop all preceding zeros in a number. For example, if i have a numbers like 000876838347 and 0000007854762543..how to make them as 876838347 and 7854762543.

What is your system? What is your shell?

[mute@geek ~/test]$ echo 0000007854762543 | awk '{ print $1+0 }'
7854762543

[mute@geek ~/test]$ expr 0000007854762543 + 0
7854762543

bash $(())

[mute@geek ~/test]$ echo $((10#0000007854762543))
7854762543
1 Like

Problem with numerical operations is most things assume numbers beginning in zero are octal.

1 Like

Here is a solution without numerical operations:

echo '0000123040' | sed 's/^0*//'
1 Like

Thanks a bunch! its worked..

If you have ksh93 then you can use builtin regexp

a=00005676570076585700
b=${a/~(E)^0*/}
echo $a
echo $b

Or

b=${a##+(0)}