Wednesday 15 June 2011

variables - Passing two values from awk to bash -


I have a list of prices in which I am the most and awk bash I am able to find these, but I am unable to assign values ​​to some variables, so I can use them later in bash .

My input:

  Number position length value 1 2 40 0.96 --- 5 45 0.97 4 5 47 0.96 --- 5 35 0.95 2 5 60 0.95 -     Minimum = $ 3} {if ($ 3> max) max = $ 3; If ($ 3 & lt; min) min = $ 3;} END {print max, minimum} 'List.txt   

Output: 60 and 35 .

I know that it is possible to send values ​​from bash to awk -v with my < Code> awk script

  variable1 = string; Awk -v variable1 = $ variable '{}'   

Is there a way to do the same thing, but to bash from awk, so i min And max ?

You can do this:

  read-r max minutes & Lt; & Lt; ($ 3 & lt; minutes) min = $ 3;} END {print max, minimum}  max) max = $ 3;   

then:

  echo $ max echo $ min   

OR:

  arr = ($ (awk 'NR == 1 {max = $ 3; Min = $ 3} {If ($ 3> max) max = $ 3; if ($ 3 & lt; min) min = $ 3;} END {print max, min} 'List.txt))   

then:

  resonant $ {arr [0]} # maximum resonance $ {arr [1]} # min   

OR:

  set - $ (awk 'NR == 1 {max = $ 3; minutes = $ 3} {if ($ 3> maximum) max = $ 3; if ( $ 3 & lt; minutes) minutes = $ 3;} END {print max, minimum} 'List.txt)   

then:

  max = $ 1 min = $ 2    

No comments:

Post a Comment