remove leading zeros in shell script

Posted on 2014-04-27
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"
Question by:welcome 123
LVL 26

Accepted Solution

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

Expert Comment

ID: 40025983

LVL 37

Expert Comment

by:Gerwin Jansen
ID: 40027689
LVL 29

Expert Comment

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

Open in new window


Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now