1 |
On Wed, 2006-08-23 at 17:20 +0200, Bo Ørsted Andresen wrote: |
2 |
> On Wednesday 23 August 2006 16:30, Ow Mun Heng wrote: |
3 |
> > (Does awk parse the file once or multiple times, that is if I were to |
4 |
> > rewrite the below entirely in awk language) |
5 |
> |
6 |
> awk parses the file only once. One line at a time. Of course that goes for |
7 |
> every invocation of awk... ;) |
8 |
> |
9 |
> > finaltpi=`cat $1 | awk "/TPI chosen/" | awk -v pat="$x" '{if |
10 |
> > (NR==pat+1) print $5}'` |
11 |
> |
12 |
> finaltpi=`awk -v pat="$x" '/TPI chosen/{if (NR==pat+1) print $5' < $x` |
13 |
> |
14 |
> > tpiert=`egrep -i "(average)" $1 | awk -v pat="$i" |
15 |
> > '{ if(NR==pat) print $5","$10}'` |
16 |
> |
17 |
> tpiert=`awk -v pat="$i" 'tolower($0)~/(average)/{ if(NR==pat) print $5","$10}' < $1` |
18 |
> |
19 |
> If you want more help with this I would suggest that you posted a short sample |
20 |
> input file and a sample of the output you want to achieve. It does make it a |
21 |
> heck of a lot easier to grasp what it is you want to do... |
22 |
|
23 |
I've managed to solve it using Etaoin's help but I'll post the input and |
24 |
output files here anyway, (as I can't understand why you're using $x in |
25 |
the 1st query. Ah.. Figured it out, you meant to use $1 (to subtitute |
26 |
the cat $1. Is there a performance difference? |
27 |
|
28 |
I can't use the 2nd invocation of awk (for tpiert) mainly because the NR |
29 |
is different |
30 |
|
31 |
$awk 'tolower($0)~/(average)/{ print NR,$5","$10}' < test |
32 |
4 1.4E+005,1.0E+000 |
33 |
6 1.9E+004,9.0E+001 |
34 |
|
35 |
it doesn't line up. the grep makes it this way |
36 |
|
37 |
$egrep -i "(average)" test | awk '{print NR,$5","$10}' |
38 |
1 1.4E+005,1.0E+000 |
39 |
2 1.9E+004,9.0E+001 |
40 |
|
41 |
HEnce I can use the NR sequentially. |
42 |
|
43 |
Thanks |
44 |
|
45 |
$cat test |
46 |
TPI chosen for x[0]: 7 |
47 |
TPI chosen for x[1]: 6 |
48 |
|
49 |
------------------------------------------------------- |
50 |
=====> average before = 1.4E+005 , average |
51 |
after = 1.0E+000 |
52 |
|
53 |
------------------------------------------------------- |
54 |
=====> average before = 1.9E+004 , average |
55 |
after = 9.0E+001 |
56 |
|
57 |
------------------------------------------------------- |
58 |
|
59 |
$cat output |
60 |
test,0,1,7,1.4E+005,1.0E+000 |
61 |
test,0,2,7,1.9E+004,9.0E+001 |
62 |
|
63 |
|
64 |
-- |
65 |
gentoo-user@g.o mailing list |