summaryrefslogtreecommitdiff
path: root/shuf.sh
diff options
context:
space:
mode:
Diffstat (limited to 'shuf.sh')
-rw-r--r--shuf.sh18
1 files changed, 18 insertions, 0 deletions
diff --git a/shuf.sh b/shuf.sh
new file mode 100644
index 0000000..d0fe4fb
--- /dev/null
+++ b/shuf.sh
@@ -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++;
+ }
+ }
+}