title: find global min/max among local extreme using awk or shell script
body: <p>I can find local min. or local max. of my two column data (x, y) by using following awk codes.</p>
  
  <pre><code>awk 'prev!=""&amp;&amp;prev&lt;=prev2&amp;&amp;prev&lt;=$2{print line}{prev2=prev;prev=$2;line=$0}' file # this is for local min.
  
  awk 'prev!=""&amp;&amp;prev&gt;=prev2&amp;&amp;prev&gt;=$2{print line}{prev2=prev;prev=$2;line=$0}' file # this is for local max.
  </code></pre>
  
  <p>Qs:</p>
  
  <ol>
  <li><p>Could you explain above codes shortly? I just used and saw it works, but don't know how it works...</p></li>
  <li><p>How could I find global min/max after local min/max are found by the above code?</p></li>
  </ol>