Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extract e.g. 211-219 to numbers... 3

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL

hello,

having "211-219" how to quick extract it to numbers:

211
212
213
214
215
216
217
218
219
 
Hi

Code:
seq 211 219
Bash:
echo {211..219}
Bash:
function iterate { for ((i=${1%-*};i<=${1#*-};i++)); do echo "$i"; done; }

iterate 211-219
Code:
function iterate { i="${1%-*}"; m="${1#*-}"; while ((i<=m)); do echo $((i++)); done; }

iterate 211-219

Feherke.
 
thx, but in ksh I gen an error...

Code:
$ ksh
$ function iterate { i="${1%-*}"; m="${1#*-}"; while ((i<=m)); do echo $((i++)); done; }
$ iterate 211-219
iterate: i++: 0403-053 Expression is not complete; more tokens expected.
$
 
Hi

Hmm... Interesting. Try to change the

[tt]echo $((i++))[/tt]

with

[tt]echo $((i+=1))[/tt]

[tt]echo $((i=i+1))[/tt]

[tt]echo $i; let i=i+1[/tt]

One of them should work.


Feherke.
 
ok, now it works.

thx.

Code:
$ function iterate { i="${1%-*}"; m="${1#*-}";i=$((i-1)); while ((i<m)); do echo $((i+=1)); done; }
$ iterate 211-219
211
212
213
214
215
216
217
218
219
$ iterate 200-219
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
$ iterate 1-7
1
2
3
4
5
6
7
$ iterate 1-1
1
$
 
A star due for Feherke then eh?

Some days are diamonds, some days are rocks - make sure most are the former.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top