idea, produce a random array, and then press the elements of the array to re-output the rows in the file 1, the generation of random array reading when it feels very simple. The first time with a little bit. The first is the definition, and the variables in the shell are weak variables that can be defined at any time. Arr= (' seq 57 ') creates a 1: An array of 57, note that you must add parentheses, otherwise you cannot define an array. You can also use a for loop to dynamically assign a value to an array. For ((i=0;i<57;i++)) #有空格 does arr[$i]=$ (($i + 1)) done again is to generate a random number using an internal variable $random, resulting in 0-327 67. #!/bin/bash arr= (' seq ") let" a= $RANDOM%57 "let" b= $RANDOM%57 "echo" a= "$a echo" b= "$b tmp=${arr[$a]} arr[$a]=${arr[$b]} #赋值的时候arr [$a], do not write ${arr[$a]} arr[$b]= $tmp echo ${arr[@]} cycle the above process 10,000 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 50 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, scrambled file line #!/bin/bash arr= (' seq ') for ((i=0;i<10000;i++)) do le T "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 #注意读取文件的写法 do (j + +) If ["$i" -eq "$j"];then echo "i= $i, j= $j: $line" echo $line >> list1.txt Break fi do < backup.txt done through the above script, feel even after reading the book, know some of the east West, or not, the important thing is to keep practicing. Even if it is a simple thing, such as an array, if judgment, and so on, can only be above his business when not written.
Shell scrambled file line