Created
March 12, 2020 23:28
-
-
Save cirrusUK/71bd249655c40292840dcedd4fce336d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/awk -f | |
| # rand-line.awk -- output a random line from input | |
| # $Id: rand-line.awk,v 1.3 1998/11/18 01:18:52 cdua Exp cdua $ | |
| # Carlos Duarte, 971027/981118 | |
| BEGIN { | |
| srand() | |
| for (i=1; i<ARGC; i++) { | |
| s = ARGV[i] | |
| if (s !~ /^-/) | |
| break; | |
| if (s == "-n" && ++i <ARGC) { | |
| ARGV[i-1] = "" | |
| n = ARGV[i] | |
| ARGV[i] = "" | |
| } else | |
| break; | |
| } | |
| if (n+0 == 0) | |
| n = 1 | |
| } | |
| { | |
| lines[cnt++] = $0 | |
| } | |
| END { | |
| while (n--) { | |
| d = int(rand()*cnt) | |
| print lines[d]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment