1836626 Members
1725 Online
110102 Solutions
New Discussion

Awk Script Help

 
SOLVED
Go to solution
Ashwin_4
Frequent Advisor

Awk Script Help

Hi Masters,
Please help me to write a shell script to get the desired output as described below:
Input file content:

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse D 0.01 0.02 0 0 0 0
Execute E 0.00 0.00 0 0 0 0
Fetch J 1.31 1.58 2169 6951 36 I
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 45 1.32 1.60 K F G H


Desired Output:

I want to display following ratios using "AWK"
i. F+G
F+G
2. ---
H

3. D/E

4. I/J
5. K
----
F+G

Thanks in advance.
Points will be awarded.


3 REPLIES 3
Laurie Gellatly
Honored Contributor

Re: Awk Script Help

Start simple and then you can build on this:
get F+G
awk "/total/ { print $6+$7 }" inputFile
Get H
awk "/total/ { print $8 }" inputfile
and you can combine them into a file (x1 say):
/total/ { print $6+$7 }
/total/ { print $8 }

and then use it
awk -f x1 inputFile

where inputFile is the file that contains your
original info.

Play with that and you can learn awk on the way.

HTH ...Laurie :{)
If you're not using OverTime, you're doing overtime!
Hein van den Heuvel
Honored Contributor

Re: Awk Script Help

Sorry, but the desired output formatting is unclear to me. Still, I'm sure you can get going using the following:

# cat x.awk
/^Par/{ d = $2}
/^Exe/{ e = $2}
/^Fet/{ j = $2}
/^tot/{ k = $5; f = $6; g = $7; h = $8;
print d,e,j,k,f,g,h;
}
END { printf "(could be part of total processing) D/E = %5.2f%%\n",100*d/e }

# cat x
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.01 0.02 0 0 0 0
Execute 3 0.00 0.00 0 0 0 0
Fetch J 1.31 1.58 2169 6951 36 I
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 45 1.32 1.60 K F G H

# awk -f x.awk < x
1 3 J K F G H
(could be part of total processing) D/E = 33.33%


Enjoy...

Hein.

curt larson_1
Honored Contributor
Solution

Re: Awk Script Help

awk '
/^Parse/ { d = $2;}
/^Execute/ { e = $2;}
/^Fetch/ { j = $2;
i = $9; }
/^total/ { f = $6;
g = $7;
h = $8;
k = $5; }
END {
printf("f+g = %d\n",f+g);
printf("(f+g)/h = %d\n",(f+g)/h);
...
}'