Sponsored Content
Top Forums Shell Programming and Scripting Digits with starting zero's in loops Post 302877539 by rbatte1 on Monday 2nd of December 2013 06:24:47 AM
Old 12-02-2013
You could also (depending on your shell, which you haven't told us, but it looks like bash)
Code:
typeset -Z3 i

This will set the value to be three digits with leading zeros as required. As a caution though, it will use the right-most three digits it your value is higher.

This can be useful sometimes, but can get in the way:-
Code:
$ typeset -Z3 i=1234
$ echo $i
234



I hope that this helps,
Robin
Liverpool/Blackburn
UK
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Only Digits as input

Hi All, I am new to shell script. I wrote a very small script that takes only digits as input- but there is some problem in that.can you help me in debugging that. #!/bin/ksh echo "Digits as input" read number digit='eval ' if ] then echo "Entered number is a digit" else echo... (2 Replies)
Discussion started by: namishtiwari
2 Replies

2. Shell Programming and Scripting

Formatting digits

I want to check the argument in KSH. If the user type in the prompt 'find 3' it will format 3 to 003 to match the data in the text file. Same as with 10 to 010. Always begins with 0. eg. >find 3 Output: 003 >find 30 Output: 030 (7 Replies)
Discussion started by: harry0013
7 Replies

3. Shell Programming and Scripting

total last digits

hi group, How can I count total number of 5's which are continuous in the end. i.e. in the below string, the o/p should be 4 I just know to calculate total number of 5's $ echo "95952325555" | awk -F "5" '{print NF-1}' 6 (3 Replies)
Discussion started by: uwork72
3 Replies

4. Shell Programming and Scripting

help: single digits inflated to 2 digits

Hi Folks Probably an easy one here but how do I get a sequence to get used as mentioned. For example in the following I want to automatically create files that have a 2 digit number at the end of their names: m@pyhead:~$ for x in $(seq 00 10); do touch file_$x; done m@pyhead:~$ ls file*... (2 Replies)
Discussion started by: amadain
2 Replies

5. Shell Programming and Scripting

Find filenames with three digits and add zeros to make five digits

Hello all! I've looked all over the internet and this site and have come up a loss with an easy way to make a bash script to do what I want to do. I have a file with a naming convention as follows: 2012-01-18 string of words here 123.jpg 2012-01-18 string of words here 1234.jpg 2012-01-18... (2 Replies)
Discussion started by: Buzzman25
2 Replies

6. UNIX for Advanced & Expert Users

How to replace last 8 digits?

Hi, How I can replace last 8 ZEROS with 22991231? 19523479811841494432A2013052700000000 19523479811730333980A2013052700000000 19523479811417044397A2013052700000000 19523479811205895810C2013010120130131 A9523479811205895810A2013020120130228 19523479811205895810I2013030120130331... (9 Replies)
Discussion started by: jnrohit2k
9 Replies

7. Programming

6 digits combination

Is there any program that can create 6 digit numbers with: (DIGIT_1)+(DIGIT_2)+(DIGIT_3)+(DIGIT_4)+(DIGIT_5)+(DIGIT_6)=10 Any perl or C also can. Anyone can help me? Thank you (6 Replies)
Discussion started by: Tzeronone
6 Replies

8. UNIX for Dummies Questions & Answers

How to grep a line not starting with # from a file (there are two lines starting with # and normal)?

e.g. File name: File.txt cat File.txt Result: #INBOUND_QUEUE=FAQ1 INBOUND_QUEUE=FAQ2 I want to get the value for one which is not commented out. Thanks, (3 Replies)
Discussion started by: Tanu
3 Replies

9. Shell Programming and Scripting

Showing 4 digits

Hello everybody I'm a little beginer for shell script as I started last night... I have this script cat fichier.txt | while read l ; do #echo $l echo $x x=$(( $x + 1 )) done it's return 1 2 3 4 (4 Replies)
Discussion started by: remibemol
4 Replies

10. UNIX for Beginners Questions & Answers

sed / awk script to delete the two digits from first 3 digits

Hi All , I am having an input file as stated below 5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 011 611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011 3486... (4 Replies)
Discussion started by: kshitij
4 Replies
NUMRANGE(1)						User Contributed Perl Documentation					       NUMRANGE(1)

NAME
numrange - Print out a range of numbers for use in for loops and such. SYNOPSIS
numrange [-dhV] /<expression>/ DESCRIPTION
numrange will print out a list of numbers based on an expression that you specify. This is useful for making a list of numbers for use in for loops and so on. Ranges are inclusive. Ranges of numbers are specified using the .. operator, like this /20..50/, which means all integers from 20 to 50 inclusive. More complex expressions can be generated using the commas and the 'i' increment operator. OPTIONS
-e <set> Exclude the <set> of numbers from the range output. <set> is a set of numbers separated by commas. -n <n> Use <n> as the separator between numbers. By default, it will use a space. Use ' ' or \n for a newline character or use the -N option. -N Just a quick option for using a newline as the separator. -h Help: You're looking at it. -V Increase verbosity. -d Debug mode. For developers EXAMPLES
All numbers from 1 to 10. $ numrange /1..10/ 1 2 3 4 5 6 7 8 9 10 From 10 to 1. Counting down. $ numrange /10..1/ 10 9 8 7 6 5 4 3 2 1 From 1 to 10 and from 15 to 20. $ numrange /1..10,15..20/ 1 2 3 4 5 6 7 8 9 10 15 16 17 18 19 20 Even numbers from 0 to 10 $ numrange /0..10i2/ 0 2 4 6 8 10 Odd numbers. Notice the starting number in the range expression. $ numrange /1..10i2/ 1 3 5 7 9 Factors of 3 between 99 and 120. $ numrange /99..120i3/ 99 102 105 108 111 114 117 120 Decimal numbers $ numrange /1.1..2.5i0.1/ 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2 2.1 2.2 2.3 2.4 2.5 And negative numbers too. $ numrange /1.0..-2.0i0.3/ 1 0.7 0.4 0.1 -0.2 -0.5 -0.8 -1.1 -1.4 -1.7 -2 You can also pad numbers when you are counting up. This is a trick of how the Perl programming language deals with ranges: $ numrange /01..15/ 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 BUGS
Even though you can do zero padding on simple ranges, like 001..100, it will not pad zeros on complex ranges like 001..100i2, or for counting downwards. SEE ALSO
seq(1), numaverage(1), numbound(1), numinterval(1), numnormalize(1), numgrep(1), numprocess(1), numsum(1), numrandom(1), numround(1) COPYRIGHT
numrange is part of the num-utils package, which is copyrighted by Suso Banderas and released under the GPL license. Please read the COPYING and LICENSE files that came with the num-utils package Developers can read the GOALS file and contact me about providing submitions or help for the project. MORE INFO
More info on numrange can be found at: http://suso.suso.org/programs/num-utils/ perl v5.10.1 2009-10-31 NUMRANGE(1)
All times are GMT -4. The time now is 08:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy