How to get the number series in between?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get the number series in between?
# 1  
Old 06-27-2011
How to get the number series in between?

Hi Guys,

Can someone give me a simple script that can extract the numbers in between numbers from start to end. As shown below, it start from 100 to 110 and revealed the numbers in between.

INPUT:
Code:
100 - 110


DESIRED OUTPUT:
Code:
100
101
102
103
104
105
106
107
108
109
110


Thanks in advance.

Br,
Pinpe
# 2  
Old 06-27-2011
Here is one way of doing it:
Code:
#!/usr/bin/ksh
mFrom=$1
mTo=$2
typeset -i mCnt=${mFrom}
while [[ ${mCnt} -ge ${mFrom} && ${mCnt} -le ${mTo} ]]; do
  echo "${mCnt}"
  mCnt=${mCnt}+1
done

Run it as "myscript From To".
This User Gave Thanks to Shell_Life For This Post:
# 3  
Old 06-27-2011
Hi,

Test next 'perl' script:
Code:
$ cat script.pl
use strict;
use warnings;

my $input = join " ", @ARGV;
my ($min, $max) = $input =~ /^\s*(\d+)\D+(\d+)\s*$/ or 
        die "Usage: perl $0 [number] - [number]\n";

print $_, "\n" for ( $min .. $max );
$ perl script.pl 100 - 110
100
101
102
103
104
105
106
107
108
109
110

Regards,
Birei
# 4  
Old 06-27-2011
Quote:
Originally Posted by Shell_Life
Here is one way of doing it:
Code:
#!/usr/bin/ksh
mFrom=$1
mTo=$2
typeset -i mCnt=${mFrom}
while [[ ${mCnt} -ge ${mFrom} && ${mCnt} -le ${mTo} ]]; do
  echo "${mCnt}"
  mCnt=${mCnt}+1
done

Run it as "myscript From To".
Perfect! Thanks dude! Smilie Smilie

Br,
Pinpe
# 5  
Old 06-27-2011
ksh, bash:
Code:
echo {100..110} | tr ' ' '\n'

with seq utility
Code:
seq 100 110

# 6  
Old 06-27-2011
Code:
#!/bin/ksh93

for (( mCnt=$1, mTo=$2; mCnt <= mTo; mCnt++ )); do
   echo $mCnt
done

# 7  
Old 06-28-2011
Using awk:
Code:
echo '100 110' | awk '{while($1<=$2)print $1++}'

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Red Hat

Find the series

Hai what command is used to find red hat linux 5 series? (2 Replies)
Discussion started by: vinayd
2 Replies

2. Shell Programming and Scripting

Finding Minimum in a Series

I have two LARGE files of data more than 20,000 line each, file-1 and file-2, and I wish to do the following if possible: file-1 1 2 5 7 9 2 4 6 3 8 9 4 6 8 9 3 2 1 3 1 2 . . . file-2 1 2 3 2 5 7 5 7 3 7 9 4 . (5 Replies)
Discussion started by: ali2011
5 Replies

3. Shell Programming and Scripting

how can I detect number series range

Hi I have one source file and content of source file as follows; 3 00 3 01 3 02 3 07 3 09 3 10 3 15 3 16 3 17 3 18 3 40 3 45 3 500 3 501 3 502 3 70 3 80 (8 Replies)
Discussion started by: kocaturk
8 Replies

4. Solaris

M Series

Hi All, Do anyone know if I upgrade cpu module and memory module for one of the domain inside Sun M5000. After the upgrade, will the hostid for the domain change or it will remain as long we don't change the system board? Currently will try to upgrade one of the Sun M5000 with 4 domains... (2 Replies)
Discussion started by: mailbox80
2 Replies

5. UNIX for Dummies Questions & Answers

To find missing numbers from a number series

Hi, My requirement is I have an input file with a continuous series from 10000 to 99999. I have some numbers missing from those series. I want a output file which produces those missing numbers. Eg: 10002, 99999 are missing from the series then the output file should contain those... (4 Replies)
Discussion started by: rakeshbharadwaj
4 Replies

6. Programming

series of combinations

HI I have a series(sorted), which i require to create combinations. I am not getting the good code for doing this. My series should generate the following combinations... Please help me in getting this in C++. Thanks for your help. A: A A B: A B A B A B C: A ... (1 Reply)
Discussion started by: rameshmelam
1 Replies

7. Programming

C with MQ Series

Hi, Any one please let me know, how to write in to MQ Series through C. I tried, but it was vein, am expecting material(URL) or code. Thanks, Naga:cool: (5 Replies)
Discussion started by: Nagapandi
5 Replies

8. Shell Programming and Scripting

Fibonacci series

Need code to run the Fibonacci series from 0 to 10 (16 Replies)
Discussion started by: nycol
16 Replies

9. Programming

Ibm Mq Series

hi everybody, My name is Raj i work in GE Global Software Solutions As Siebel Analyst. Can any one help in writing the code in Ansi C on HP-Unix platform to get data from IBM MQ-Series Server. IBM MQ-series client will be installed on the client machine which is on WIN NT platform. And MQ-series... (2 Replies)
Discussion started by: garimella
2 Replies
Login or Register to Ask a Question