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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AIX Equivelant to "seq"

Status
Not open for further replies.

bambock

Programmer
Oct 26, 2005
60
US
Does anyone know of a command that utility or method via the shell that is equivelant to the seq command in Linux? For instance, from the command line I want to run a command 30 times, the seq command allows this in the example below:

Code:
# for i in `seq 1 30`
> do
> print $i
> done

man seq:
Thanks.
Ethan
 
own scripting possibly (no checking of number of parameters, or their values is provided in this example):

Code:
beg=$1
end=$2
seq=''
while ((beg<=end))
do
 seq="$seq $beg"
 ((beg=beg+1))
done
echo $seq

HTH,

p5wizard
 
Hi,

Using p5wizard code in a convenient way

Code:
#/usr/bin/ksh 
# declaring p5wizard function
function seq {
beg=$1
end=$2
seq=''
while ((beg<=end))
do
 seq="$seq $beg"
 ((beg=beg+1))
done
echo $seq
}

# calling seq function
for i in $(seq 25 30)
do
        print $i
done
 
Use the bash shell seq is available...

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
I lied

It's available in


Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
$ echo '0 30' | awk '{ for (i=$1;i<=$2;i++) { print i} }'

my way :)
 
another short way:

for i in $(yes|head -30)
do
# this block gets run 30 times, but you lose the number
# i is set to 'yes' each time
echo $i
done

or if you're feeling negative:

for i in $(yes no|head -30)
do
# i is set to 'no' each time
echo $i
done


HTH,

p5wizard
 
It wouldn't be rocket science to write 'seq'
Something along the lines of
Code:
#!/bin/ksh

[[ $# -eq 2 ]] || exit 1;
[[ $2 -ge $1 ]] || exit 1
while [ $1 -le $2 ]
do
  echo $1
  (( $1 += 1 ))
done
and stick it somewhere on your path.

Ceci n'est pas une signature
Columb Healy
 
it can be a function also:

seq()
{
[[ $# -eq 2 ]] &&\
[[ $2 -ge $1 ]] &&\
[[ $1+0 -eq $1 ]] &&\
[[ $2+0 -eq $2 ]] &&\
yes ''|nl -ba|head -$2|tail +$1
}


HTH,

p5wizard
 
p5wizard
Neat way to check for ints!

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top