coreutils: shuf invocation
1
1 7.2 ‘shuf’: Shuffling text
1 ==========================
1
1 ‘shuf’ shuffles its input by outputting a random permutation of its
1 input lines. Each output permutation is equally likely. Synopses:
1
1 shuf [OPTION]... [FILE]
1 shuf -e [OPTION]... [ARG]...
1 shuf -i LO-HI [OPTION]...
1
1 ‘shuf’ has three modes of operation that affect where it obtains its
1 input lines. By default, it reads lines from standard input. The
1 following options change the operation mode:
1
1 ‘-e’
1 ‘--echo’
1 Treat each command-line operand as an input line.
1
1 ‘-i LO-HI’
1 ‘--input-range=LO-HI’
1 Act as if input came from a file containing the range of unsigned
1 decimal integers LO...HI, one per line.
1
1 ‘shuf’’s other options can affect its behavior in all operation
1 modes:
1
1 ‘-n COUNT’
1 ‘--head-count=COUNT’
1 Output at most COUNT lines. By default, all input lines are
1 output.
1
1 ‘-o OUTPUT-FILE’
1 ‘--output=OUTPUT-FILE’
1 Write output to OUTPUT-FILE instead of standard output. ‘shuf’
1 reads all input before opening OUTPUT-FILE, so you can safely
1 shuffle a file in place by using commands like ‘shuf -o F <F’ and
1 ‘cat F | shuf -o F’.
1
1 ‘--random-source=FILE’
1 Use FILE as a source of random data used to determine which
1 permutation to generate. ⇒Random sources.
1
1 ‘-r’
1 ‘--repeat’
1 Repeat output values, that is, select with replacement. With this
1 option the output is not a permutation of the input; instead, each
1 output line is randomly chosen from all the inputs. This option is
1 typically combined with ‘--head-count’; if ‘--head-count’ is not
1 given, ‘shuf’ repeats indefinitely.
1
1 ‘-z’
1 ‘--zero-terminated’
1 Delimit items with a zero byte rather than a newline (ASCII LF).
1 I.e., treat input as items separated by ASCII NUL and terminate
1 output items with ASCII NUL. This option can be useful in
1 conjunction with ‘perl -0’ or ‘find -print0’ and ‘xargs -0’ which
1 do the same in order to reliably handle arbitrary file names (even
1 those containing blanks or other special characters).
1
1 For example:
1
1 shuf <<EOF
1 A man,
1 a plan,
1 a canal:
1 Panama!
1 EOF
1
1 might produce the output
1
1 Panama!
1 A man,
1 a canal:
1 a plan,
1
1 Similarly, the command:
1
1 shuf -e clubs hearts diamonds spades
1
1 might output:
1
1 clubs
1 diamonds
1 spades
1 hearts
1
1 and the command ‘shuf -i 1-4’ might output:
1
1 4
1 2
1 1
1 3
1
1 The above examples all have four input lines, so ‘shuf’ might produce
1 any of the twenty-four possible permutations of the input. In general,
1 if there are N input lines, there are N! (i.e., N factorial, or N * (N
1 - 1) * ... * 1) possible output permutations.
1
1 To output 50 random numbers each in the range 0 through 9, use:
1
1 shuf -r -n 50 -i 0-9
1
1 To simulate 100 coin flips, use:
1
1 shuf -r -n 100 -e Head Tail
1
1 An exit status of zero indicates success, and a nonzero value
1 indicates failure.
1