shuf命令簡單用法


shuf命令簡單用法

背景:需要將一個文件的內容按照行進行打亂順序;需要從一個大文件中隨機獲取多少行的內容,除了python腳本處理以外,一些shell命令也可以更快捷的做到

shuf命令詳解

bash-4.1$ shuf --help
Usage: shuf [OPTION]... [FILE]
  or:  shuf -e [OPTION]... [ARG]...
  or:  shuf -i LO-HI [OPTION]...
Write a random permutation of the input lines to standard output.

Mandatory arguments to long options are mandatory for short options too.
  -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
  -z, --zero-terminated     end lines with 0 byte, not newline
      --help     display this help and exit
      --version  output version information and exit

With no FILE, or when FILE is -, read standard input.

Report shuf bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'shuf invocation'
# 例1:將一個文件順序打亂輸出到另一個文件
shuf a.txt > b.txt
shuf a.txt -o b.txt  # 以文件格式輸出到b

# 例2:將一個文件中的數據隨機獲取50條數據存到另一個文件中
shuf a.txt -o b.txt -n 30


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM