title: How to make this awk script simple and use in gnuscript in loop form
body: <p>I am attempting to plot a multicolum file using gnuplot script.
  I am doing it like</p>
  
  <pre><code>plot "100.dat" u ($1-CONS):($2*$3)  w l lt 4 , 
  "200.dat" u ($1-CONS):($2*$3)  w l lt 2 , 
  "300.dat" u ($1-CONS):($2*$3)  w l lt 1
  </code></pre>
  
  <p>where CONS is my variable defined at the top of file.</p>
  
  <p>My set xrange is [-0.2:0.2] while data in the scale is beyond this scale.</p>
  
  <p>What I want to capture is (in loop form for multiple files):
  maximum value  of above three plots in negative and positive both sides and corresponding value of column 1 in my xrange for both the maximum.</p>
  
  <p>in a shell script I can do it easily but I am facing problem in defining in my gnuscript
  my shell script is below </p>
  
  <pre><code>for i in 100.0000 200.0000 200.0000
  do
      grep $i data.dat &gt; $i.dat
  
  
  
  awk '{print ($1-CONS), ($2*$3)}' $i.dat | awk '{ if($1 &lt;= 0.2 &amp;&amp; $1 &gt;= 0.0) { print }}' &gt; $i.p2.dat ; awk 'BEGIN {min=1000000; max=0;}; { if($2&lt;min &amp;&amp; $2 != "") min = $2; if($2&gt;max &amp;&amp; $2 != "") max = $2; } END {print min, max}' $i.p2.dat  | awk '{print $2}' &gt; $i.p2Max.dat ;  PMAX=$(cat $i.p2Max.dat) ; grep "$PMAX"  $i.p2.dat  | tail -n 1 &gt;&gt; MAX.dat
  
  
  
  awk '{print ($1-CONS), ($2*$3)}' $i.dat | awk '{ if($1 &lt;= 0.0 &amp;&amp; $1 &gt;= -0.2) { print }}' &gt; $i.mi.dat ; awk 'BEGIN {min=1000000; max=0;}; { if($2&lt;min &amp;&amp; $2 != "") min = $2; if($2&gt;max &amp;&amp; $2 != "") max = $2; } END {print min, max}' $i.mi.dat  | awk '{print $2}' &gt; $i.mi_Max.dat ;  N_MAX=$(cat $i.mi_Max.dat) ; grep "$N_MAX"  $i.mi.dat  | tail -n 1 &gt;&gt; MAX.dat
  done
  </code></pre>
  
  <p>I am looking for a simple script that can be used in the gnuplot script in loop form so that if I have multiple data file and I need to grep the maximum of a colum two (on both the sides of the zero) then it store the maximum value  of column two wrt  corresponding value of column 1 separately for negative and positive scale. </p>
  
  <p>I would love to see if this can be done using a loop so that I do not need to write all the lines repetitively. </p>