Solved

remove leading zeros in shell script

Posted on 2014-04-27
4
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 38

Expert Comment

by:Gerwin Jansen, EE MVE
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

719 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