Solved

remove leading zeros in shell script

Posted on 2014-04-27
4
346 Views
Last Modified: 2014-04-30
I need help in shell script to remove leading zeros from a number

for example: x= "01"
and I need the result x= "1" or in another variable y="1"
0
Comment
Question by:welcome 123
4 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 40025947
y="$(echo $valueWithZeroes | sed 's/0*//')"
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40025983
x=$((x))

x=${x#0}
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
ID: 40027689
x=$(bc<<<$x)
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 40029425
Or just convert to integer:
(( x += 0 ))

Open in new window

:p
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
EXCHANGE 2007, SCRIPTS 67 78
powershell code to list items in dropdown 6 60
Run same command on multiple files in Linux 3 30
remove one line from a file in solaris 8 28
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question