Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

remove leading zeros in shell script

Posted on 2014-04-27
4
Medium Priority
?
374 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

609 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