diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-07-26 21:10:54 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-07-26 21:10:54 -0400 |
commit | 4c16e777b2994a0aa962a9e7bc1bda7e4f8676fd (patch) | |
tree | 5f469a5adda9276b864ba15895477d5b1c3420f9 | |
parent | 1d151651323894437cc7cfb3895f2f7e651c5294 (diff) |
implement shuf
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | shuf | 0 | ||||
-rw-r--r-- | shuf.sh | 18 |
4 files changed, 20 insertions, 1 deletions
@@ -9,6 +9,7 @@ nproc pinky printenv readlink +shuf seq stdbuf tac @@ -1,7 +1,7 @@ .POSIX: PROGRAMS=arch base64 factor hostid mktemp nproc pinky printenv readlink \ - seq stdbuf sync tac uptime users vdir yes + seq shuf stdbuf sync tac uptime users vdir yes all: $(PROGRAMS) @@ -0,0 +1,18 @@ +exec awk "$(tail -n +2 $0)" "$@" + +{ + lines[NR] = $0; + printed[NR] = 0; +} + +END { + nprinted = 0; + while (nprinted < NR) { + line = int(rand() * NR); + if (!printed[line]) { + print lines[line]; + printed[line] = 1; + nprinted++; + } + } +} |