Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the shuf command in Linux

Shulou Source: shulou.com Published: 2022-06-01 16:11:52 10月02日 Update

This article mainly shows you "how to use the shuf command in Linux". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn how to use the shuf command in Linux.

The Linux common command shuf command is used to output input lines to standard output in random order.

Syntax format shuf [options]... [file] or: shuf-e [option]. [parameter]. Or: shuf-I LO-HI [option]. Parameter-e,-- echo treats each parameter as input line-I,-- input-range=LO-HI treats each number from LO to HI as input line-n,-- head-count= lines up to output the specified number of lines-o,-- output= file outputs the result to the specified file instead of standard output-- the random-source= file gets random bits-z from the specified file. -- zero-terminated ends line with 0 instead of new line-- help displays this help and exits-- version displays version information and exits if no file is specified Or if the file is "-", it is read from standard input. Example 1

[tank@localhost test1] # cat 1.txt # ordered 1 2 3 4 5 6 [tank@localhost test1] # shuf 1.txt # disordered 6 2 3 5 4 1 cases 2

[root@pf] # shuf-e 1 2 3 4 5 6 1 2 6 4 3 5 [root@pf] # shuf-I 1-6 6 5 4 2 3 1 [root@pf] # shuf-N3-I 1-6 4 51 [root@pf] # shuf-N3-I 1-6-o out.txt [root@pf] # cat out.txt 546 cases 3

Let me share an example of simulating a two-color ball with a shuf command: # define an array of red balls and basketball. # RED= `seq 16` # BLUE= `seq 33` # one ball is randomly selected from the red ball array. # echo "Red Ball:"; echo "${RED [@]}" | shuf-N1 # does not put back and extract 6 balls in the basketball array # echo "Blue Ball:"; echo "${BLUE [@]}" | shuf-n6 is all the contents of the article "how to use the shuf command in Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: File command output input content parameter array standard article help information basketball learning extraction order example two-color two-color ball example commonly used Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS vpn Microsoft Shulou Technology