bash, find nearest next value, forward and backward

前端 未结 4 1061
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-16 08:51

I have a data.txt file

1    2     3    4      5       6        7   
cat data.txt
13 245 1323 10.1111 10.2222 60.1111 60.22222
13 133 2325 11.2222 11.333  61.         


        
4条回答
  •  失恋的感觉
    2021-01-16 09:38

    For the first part:

    awk -v v1="11.6667" '$4>v1 {print $4;exit}' file
    12.3333
    

    And second part:

    awk -v v2="62.9997" '$6>v2 {print p;exit} {p=$6}' file
    62.3333
    

    Both in one go:

    awk -v v1="11.6667" -v v2="62.9997" '$4>v1 && !p1 {p1=$4} $6>v2 && !p2 {p2=p} {p=$6} END {print p1,p2}' file
    12.3333 62.3333
    

提交回复
热议问题