Home>

a # num b c d
0 131 3442 43465436
1000 331 42674 0.974549
2000 42424 59879 1358400
3000 242428 46846 54054540




There is a text file like the one above.
Of these, I want to find the maximum value in the third column from the left, and the number in the first column from the left in the same row.

In this case, I want to get the number 2000, because I want to move a file like aaa_2000.sh.

cat file.txt | awk '{if (m<$3) m = $3} END {print m}'
c


Now such an answer is returned.
How can I rewrite it? Also, how can I copy a file that contains the numbers in column a when I know the maximum value from a location?

Please tell me. Thank you.

  • Answer # 1

    cat file.txt | awk '{if (m<$3) {m = $3;a = $1;}} END {print a}'

    What about

    ?

  • Answer # 2

    cat file.txt | awk 'NR>1 {if (m<$3) {m = $3;a = $1;}} END {print a } '


    It was made with. Thank you very much.

Related articles