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.)
.. or install macports and do a
$ 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
Yeah, but it’s called ‘seq’ in all the scripts I have, and it wouldn’t be worth me having macports for just one command.
Hi, agreed, it bothers me too…. so much did i want this functionality without needing to do darwin ports … and having seen your recent post on this topic, i’ve just knocked together a 2 min bash script to add this functionality without actually installing anything,
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 “;
sudo ln -s /opt/local/bin/gseq /opt/local/bin/seq
🙂
see the second comment, Robert. And /opt is a crime against nature!
Oh, and there’s also always ‘jot’, seq’s weird hippie cousin which is installed by default: https://web.archive.org/web/20110105235757/http://www.nevdull.com/2007/09/24/gnu-seqs-cousin-on-freebsd-is-jot/
Nice try with that shell, Markus. It would work for maybe 80% of uses, but would fail for the rest.
Playing with jot a bit (I’m on a train), I rather like it. What jot can do in one command
jot -w %02x 255 0
(printing hexadecimal numbers 00 .. ff) seq needs a composite command:
seq 0 255 | xargs -n1 printf “%02x\n”
neat!
Just an improvement of the bash script (which doesn’t yet work properly for jot with an increment). Further improvement is welcome !
#!/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
thanks. WordPress may have munged the quotes – I hate when it does that.
Thanks, but the seq builds are for PPC and not for intel.
but the macports idea is good!
erm, but the sh-utils build trick is platform-neutral.
If you’re using BASH (the default in OS X), try just using the curly braces BASH expansion:
for i in {1..10}; do echo $i; done
just install coreutils and then link to /usr/bin
1. sudo port install coreutils
2. which gseq
3. sudo ln -s /opt/local/bin/gseq /usr/bin/seq
err, installing macports and coreutils is a bunch of work. And I still stand by what I said about /opt – if not more so!
I like the bash solution best of all, ‘cos I don’t have a single machine without it.
The curly brackets doesn’ t seem to work on all platforms. i am using bash on 10.4 and it doesn’ t recognizes it. jot worked fine and I didn’ t have to install anything. Thanks for the tip!
I created a very similar tool in Python: http://python.pastebin.com/Ubcy1xdp. It features a subset of original seq options, providing all of the essential ones, though.
I’m now totally at one with jot, and wish it were on all my systems.
sudo port install coreutils
sudo ln -sf /opt/local/bin/gseq /opt/local/bin/seq
yes, crasyboy – but jot is actually much easier to use, and more flexible. Double win!