Solved

remove leading zeros in shell script

Posted on 2014-04-27
4
350 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Remote install of MSI file 4 53
Bash Script to Analyze Oracle Schemas 11 124
Martian Packets Unix 5 72
lunix and unix command 21 115
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
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…
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.
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.

735 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