【shell】shuf命令提取文件的隨機行
shuf命令可以隨機提取一個文本文件的不同行,輸出到文件或者標準輸出中。
shuf
用法: shuf [選項]... [文件]
或者: shuf -e [選項]... [參數]...
或者: shuf -i LO-HI [選項]...
Write a random permutation of the input lines to standard output.
如果沒有指定文件,或者文件爲"-",則從標準輸入讀取。
必選參數對長短選項同時適用。
-e, --echo treat each ARG as an input line
-i, --input-range=LO-HI treat each number LO through HI as an input line
-n, --head-count=COUNT output at most COUNT lines
-o, --output=FILE write result to FILE instead of standard output
--random-source=FILE get random bytes from FILE
-r, --repeat output lines can be repeated
-z, --zero-terminated line delimiter is NUL, not newline
--help 顯示此幫助信息並退出
--version 顯示版本信息並退出
例如:提取一個input.txt中的隨機20行
shuf input.txt -n 20 -o output.txt