Reputation: 422
I have a simple histogram like this:
1.5 1.34
2.5 5.23
3.5 7.34
4.5 4.23
5.5 3.23
6.5 2.22
7.5 1.94
8.5 5.43
9.5 9.13
I need to find the minimum vale of the second column which is after the first maximum vale, and print out the corresponding value of the first colum. so I should get this output:
7.5 1.94
Could anyone suggest a nice solution for this?
Upvotes: 1
Views: 173
Reputation: 58371
This might work for you:
sort -k2,2n file | awk 'NR<2{max=$1} FNR<NR && $2>=max{print;exit}' file -
or this:
awk 'NR<2{max=$1}$2<max{next}min==0{line=$0;min=$2}$2<min{line=$0;min=$2}END{print line}' file
Upvotes: 1
Reputation: 16740
awk 'NR == 1 {my=$2;max_found=0}
!max_found && $2 > my {my=$2}
!max_found && $2 < my {mx=$1;my=$2;max_found=1}
max_found && $2 < my {mx=$1;my=$2}
max_found && $2 > my {exit}
END{print mx " " my}'
Upvotes: 1
Reputation: 16740
awk 'NR == 1 {mx=$1;my=$2}
$2 < my {mx=$1;my=$2}
$2 == my && $1 > mx {mx=$1;my=$2}
END{print mx " " my}'
Upvotes: 2