On Wed, 2006-08-23 at 17:20 +0200, Bo Ørsted Andresen wrote:
> On Wednesday 23 August 2006 16:30, Ow Mun Heng wrote:
> > (Does awk parse the file once or multiple times, that is if I were to
> > rewrite the below entirely in awk language)
> 
> awk parses the file only once. One line at a time. Of course that goes for
> every invocation of awk... ;)
> 
> >     finaltpi=`cat $1 | awk  "/TPI chosen/" | awk -v pat="$x" '{if
> > (NR==pat+1) print $5}'`
> 
> finaltpi=`awk -v pat="$x" '/TPI chosen/{if (NR==pat+1) print $5' < $x`
> 
> >                      tpiert=`egrep -i "(average)" $1 | awk -v pat="$i"
> > '{ if(NR==pat) print $5","$10}'`
> 
> tpiert=`awk -v pat="$i" 'tolower($0)~/(average)/{ if(NR==pat) print 
> $5","$10}' < $1`
> 
> If you want more help with this I would suggest that you posted a short sample
> input file and a sample of the output you want to achieve. It does make it a
> heck of a lot easier to grasp what it is you want to do...

I've managed to solve it using Etaoin's help but I'll post the input and
output files here anyway, (as I can't understand why you're using $x in
the 1st query. Ah.. Figured it out, you meant to use $1 (to subtitute
the cat $1. Is there a performance difference?

I can't use the 2nd invocation of awk (for tpiert) mainly because the NR
is different

$awk 'tolower($0)~/(average)/{ print NR,$5","$10}' < test     
4 1.4E+005,1.0E+000
6 1.9E+004,9.0E+001

it doesn't line up. the grep makes it this way

$egrep -i "(average)" test | awk '{print NR,$5","$10}'
1 1.4E+005,1.0E+000
2 1.9E+004,9.0E+001

HEnce I can use the NR sequentially.

Thanks

$cat test 
TPI chosen for x[0]: 7
TPI chosen for x[1]: 6

-------------------------------------------------------
                         =====> average before = 1.4E+005 ,   average
after = 1.0E+000 

-------------------------------------------------------
                         =====> average before = 1.9E+004 ,   average
after = 9.0E+001 

-------------------------------------------------------

$cat output
test,0,1,7,1.4E+005,1.0E+000
test,0,2,7,1.9E+004,9.0E+001


-- 
[email protected] mailing list

Reply via email to