seq for OS X
It has always irked me that OS X doesn’t have the seq command (I am easily irked). Brian Peterson’s old e-mail Re: seq from core utils has it, but the link to sh-utils doesn’t work any more, since the project has been archived. Here’s the new link: http://ftp.gnu.org/old-gnu/sh-utils/. Compile it as Brian suggested, and all will be well.
$ seq 1 12 1 2 3 4 5 6 7 8 9 10 11 12
Joy!
(at least 99% of you will be mystified why anyone would want this.)
February 21st, 2008 at 13:44:53
$ sudo port install coreutils
which will get you a gseq:
$ gseq 1 12
1
2
3
4
5
6
7
8
9
10
11
12
February 21st, 2008 at 15:23:21
March 25th, 2008 at 19:04:13
i just made this script and called it /usr/bin/seq
chmod +x /usr/bin/seq
and i’m good to go..
… i also hope this posts ok…. i have a feeling it may get filtered by the forum… maybe you can figure it out again
#!/bin/bash
# marks rude seq replacement for osx.
if [ $# -eq 2 ]
then
let from=”$1″;
let to=”$2″;
elif [ $# -eq 1 ]
then
let from=”0″;
let to=”$1″;
else
echo “USAGE: seq [num from] [num to]”
exit 1;
fi
while [ $from -lt $to ]
do
printf “$from “;
from=$[$from+1]
done
printf “$from “;
April 15th, 2008 at 09:44:06
April 15th, 2008 at 19:19:53
April 15th, 2008 at 19:28:00
Nice try with that shell, Markus. It would work for maybe 80% of uses, but would fail for the rest.
April 15th, 2008 at 19:39:05
jot -w %02x 255 0
(printing hexadecimal numbers 00 .. ff) seq needs a composite command:
seq 0 255 | xargs -n1 printf “%02x\n”
neat!
May 28th, 2008 at 07:26:33
#!/bin/bash
# marks rude seq replacement for osx.
# set -ex
method=1
case ${method} in
1)
# a simple bash script:
if [ $# -eq 2 ]
then
let from=”$1″;
let to=”$2″;
let step=1
elif [ $# -eq 1 ]
then
let from=”0″;
let to=”$1″;
let step=1
elif [ $# -eq 3 ]
then
let from=”$1″
let to=”$3″
let step=”$2″
else
echo “USAGE: seq [num from] [[num step]] [num to]”
exit 1;
fi
while [ $from -le $to ]
do
printf “$from \n”;
from=$[$from+$step]
done
;;
2)
# Using the jot command:
if [ $# -eq 2 ]
then
let numstep=`expr ‘(’ $2 - $1 + 1 ‘)’ `
jot $numstep $1 $2
elif [ $# -eq 3 ]
then
let numstep=`expr ‘(’ $3 - $1 + 1 ‘)’ / $2 `
let to=`expr $3 - ‘(’ ‘(’ $3 - $1 + 1 ‘)’ % $numstep ‘)’ `
jot ${numstep} $1 $to
else
echo “USAGE: seq [num from] [[num step]] [num to]”
exit 1;
fi
;;
esac
May 28th, 2008 at 08:33:05
June 23rd, 2008 at 18:31:35
but the macports idea is good!
June 23rd, 2008 at 22:20:36