I want to find the minimum of the 5th column of a file in every 12th interval of that and save the associated line into a new file. To find the minimum of the last 12th line I can usetail -n 12  $FILEname | sort -g -k 5,5 | head -1|  awk '{print}'> tmp.outBut how can I perform such a process iteratively?I have triedwhile read $FILEnamedo ....donewhich was not successful.The file looks like4.7 0.17    0.529   0   4.48464.7 0.17    0.529   1   4.54374744.7 0.17    0.529   2   5.632297394.7 0.17    0.529   3   4.6723851574.7 0.17    0.529   4   4.6989224684.7 0.17    0.529   5   4.6999771954.7 0.17    0.529   6   4.6999693294.7 0.17    0.529   7   3.699997174.7 0.17    0.529   8   4.69999984.7 0.17    0.529   9   2.74.7 0.17    0.59    10  3.99999984.7 0.17    0.59    11  4.699999999985   1   0.59    0   4.495698465   1   0.59    1   4.543305745   1   0.59    2   4.637396535   1   0.59    3   3.672339575   1   0.59    4   4.69892024685   1   0.59    5   4.6999125955   1   0.59    6   4.69993295   1   0.59    7   4.699999997175   1   0.59    8   4.699999985   1   0.59    9   3.25475   1   0.529   10  4.699999999985   1   0.529   11  4.69999999998with almost 2000 lines.
How to find the min of a column in every nth intervals of a file, using sed, sort, tail?
text processing;awk;sed
tryawk 'NR%12 == 1 { min=$5 ; line=$0; }     { if ($5 < min) { min=$5 ;line=$0; } }     NR%12 == 0 { print line ;}     END { if (NR%12) print line ;} ' this basically reset min every 12 lines (1,13,25, ...), compute min, and print it for line 12,24,36,...END statement print last min if number of line is not a multiple of 12.note that you can one line this statement, call it withawk '....' input_file.txt