Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Another one for obscure but useful: jot

# print 10 values from 1 to 10, with leading zeros:

for n in `jot -w "%04d" 10 1 10`; do echo $n; done



Just use Bash's builtin things:

for n in {0001..0010}; do echo ${n}; done


Nice, but this needs an actual version of bash, with that oldie shipped with OSX Yosemite the result is not padded with zeros.


Cool, thanks.


Or seq -f %04g 1 10


Sure seq is OK, but jot does everything seq does and more, so I prefer jot.

# generate 10 random numbers between 1 and 1 million

jot -r 10 1 1000000


I meant to go all "just use coreutils, there is shuf available already, no need for some third-party tool" but then I realised that jot is an integral part of BSD. Rock on! :)

For us Linuxers: shuf -i 1-1000000 -n 10




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: