pinpe
June 27, 2011, 4:33pm
1
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:
100 - 110
DESIRED OUTPUT:
100
101
102
103
104
105
106
107
108
109
110
Thanks in advance.
Br,
Pinpe
Here is one way of doing it:
#!/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".
1 Like
birei
June 27, 2011, 4:53pm
3
Hi,
Test next 'perl' script:
$ 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
yazu
June 27, 2011, 9:03pm
5
ksh, bash:
echo {100..110} | tr ' ' '\n'
with seq utility
seq 100 110
#!/bin/ksh93
for (( mCnt=$1, mTo=$2; mCnt <= mTo; mCnt++ )); do
echo $mCnt
done
Using awk:
echo '100 110' | awk '{while($1<=$2)print $1++}'