Thursday, October 06, 2005

[UNIX] seq (in Linux) equivalent

#
# Bourne shell functions similar to 'seq' in linux, except without step
# you can use it to do this in a for loop
# for i in `range 1 100`
# do
#    do-something
# done
#
range1()
{
 start=$1
 end=$2
 count=$start
 rc=""
 while [ $count -le $end ]
 do
  rc="$rc $count"
  count=`expr $count + 1`
 done
 echo $rc
}
range2()
{
 perl -e "\$,=\" \"; print $1..$2;"
}
range3()
{
 gawk -v s=$1 -v e=$2 'END{for(i=s;i<=e;++i) {printf("%d ",i)}}' /dev/null
}
range4()
{
 echo "for {set i $1} {\$i<=$2} {incr i} {puts -nonewline \"\$i \"}" | tclsh
}
range5()
{
 yes | pr -f -n | head -`expr $2 + 3` | tail -`expr $2 - $1 + 1` | cut -c1-5
}

1 Comments:

Blogger Askinstoo said...

Just thought I'd let you know about a site where you can make over $800 a month in extra income. Go to this site   MAKE MONEY NOW  and put in your zip code..... up will pop several places where you can get paid to secret shop, take surveys, etc.  It's free.  I found several and I live in a small town!

1:57 PM  

Post a Comment

<< Home