awk command: column operations

I have a txt file with two columns

Freq    Loss
10         30
20         40
30         10
40         50
50         60

i have used the below code to get the minimum value out of this array in second cloumn.

awk 'NR==N{min=$N;max=$N}NR>N{if ($N>max){max=$N};if ($N<min){min=$N}}END {print ""min" "max}' $dummyfile.arr

my code finds out the minimum in second coulmn, but

1) I want to get correcponding Freq for tht minimum value

---------- Post updated at 12:08 PM ---------- Previous update was at 12:06 PM ----------

I want to output that freq to a txt file

awk 'NR==1{min=$2}{a[$2]=$1;if($2<min)min=$2}END{print "Min Loss: "min," Freq: "a[min]}' file > out.txt
1 Like

Do you need ouput the freq or both freq & loss?

$ cat urfile

Freq    Loss
10         30
20         40
30         10
40         50
50         6

$ awk 'NR==1 {print;loss=999999;next} {if (loss>$2) {loss=$2;freq=$1}}END {print freq "\t" loss}' urfile

Freq    Loss
30      10

1 Like
awk 'END{print l}{if(i>=$2||!i){i=$2;l=$2FS$1}}' file
1 Like