DEV Community

Discussion on: Write a simple but impactful script

Collapse
 
dmfay profile image
Dian Fay

Bash:

for i in {0..9999}; do printf "%04d\n" $i; done | sort -R > pins.txt

Collapse
 
moopet profile image
Ben Sinclair

Shorter: seq -w 9999 | shuf > pins.txt

Collapse
 
rrampage profile image
Raunak Ramakrishnan • Edited

Using shuf utility for shuffling:

for i in {0..9999}; do printf "%.4d\n" $i; done | shuf > pins.txt

The two scripts are equivalent as the man sort page tells that -R option uses shuf.

Collapse
 
joshcheek profile image
Josh Cheek

I don't have sort -R or shuf (I'm on OS X). I did not know you could do the dot precision thing with integers! My solution was basically the same, but I did "%04d\n"

Thread Thread
 
dmfay profile image
Dian Fay

You can get gshuf if you install the GNU coreutils through homebrew or ports.

Thread Thread
 
joshcheek profile image
Josh Cheek

Ahh, there we go _^