The implementation method of shell randomly extracting several rows from file _linux shell

Source: Internet
Author: User

Shuf-n5 Main.txt

Sort-r Main.txt | Head-5

awk-vn=5-vc= "' wc-l file '" ' Begin{srand () while (n<n) {I=int (rand () *c+1); if (!) ( I in a)} {A[i]++;n++}}}nr in a ' file

While read Line;do echo "$line $RANDOM";d One < Main.txt | sort-k2,2n| awk ' Nr<=5{print $} '

Options for the Shuf command:

-E,--echo: treat each parameter as an input line
-I,--input-range=lo-hi: treats every number LO to HI as an input line
-N,--head-count= number of rows: Maximum output specified number of rows
-O,--output= file: Output results to specified file rather than standard output
--random-source= file: Get random bits from the specified file
-Z,--zero-terminated: ending a row with 0 instead of a new line
--help: Displays this help information and exits
--version: Display version information and exit

Example:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.