Shell breaks down file lines,
The idea is to generate a random array, and then output the row in the file according to the array elements. 1. It is very easy to generate a random array. It was a little difficult to start using it for the first time. The first is definition. The variables in shell are weak variables that can be defined at any time. Arr = ('seq 57 ') to create an array of 1 .. 57. Be sure to add parentheses. Otherwise, the array cannot be defined. You can also use the for loop method to dynamically assign values to arrays. For (I = 0; I <57; I ++) # do arr [$ I] = $ ($ I + 1) with spaces )) once again, done generates a RANDOM number and uses the internal variable $ RANDOM to generate a RANDOM number ranging from 0 to 32767. #! /Bin/bash arr = ('seq 57 ') let "a = $ RANDOM % 57" let "B = $ RANDOM % 57" echo "a =" $ a echo "B =" $ B tmp =$ {arr [$ ]} arr [$ a] =$ {arr [$ B]} # When assigning values, arr [$ a], do not write $ {arr [$ a]} arr [$ B] = $ tmp echo $ {arr [@]} to loop the process 10000 times 44 13 48 53 22 15 35 28 1 31 8 49 4 34 6 55 20 32 26 40 18 37 16 43 9 27 25 42 2 3 11 56 46 24 41 7 12 54 30 45 47 17 23 33 10 51 19 52 38 57 14 29 36 39 5 212, disrupting file lines #! /Bin/bash arr = ('seq 57 ') for (I = 0; I <10000; I ++ )) do let "a = $ RANDOM % 57" let "B = $ RANDOM % 57" tmp =$ {arr [$ a]} arr [$ a] =$ {arr [$ b]} arr [$ B] = $ tmp done # echo $ {arr [@]} for I in $ {arr [@]} do j = 0 while read line # Note do (j ++ )) if ["$ I"-eq "$ j"]; then echo "I = $ I, j = $ j: $ line "echo $ line> list1.txt break fi done <backup.txt done through the above script, I feel that even if I have read the book, I still cannot understand something, it is important to keep practicing. Even simple things, such as arrays and if judgments, can only be easy to use without writing.