AWK: add and sum line in output


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers AWK: add and sum line in output
# 8  
Old 08-28-2012
I'm sorry for the misunderstanding, my complete output is:

Code:
                 extended device statistics
device    r/s    w/s   kr/s   kw/s wait actv  svc_t  %w  %b
sd1       0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
sd5       0.1    2.9    2.6   24.8  0.0  0.1   21.0   0   1
sd6       0.1    2.9    2.7   24.8  0.0  0.1   21.1   0   1
sd7       0.0    0.0    0.0    0.0  0.0  0.0    0.2   0   0
sd8       0.0    0.0    0.0    0.0  0.0  0.0    0.1   0   0
ssd1      0.0    0.0    0.0    0.0  0.0  0.0    0.3   0   0
ssd3      0.0    0.0    0.0    0.0  0.0  0.0    0.3   0   0
ssd6      0.0    0.0    0.0    0.0  0.0  0.0    0.3   0   0
ssd10     0.0    0.0    0.0    0.0  0.0  0.0    0.3   0   0
ssd12     0.0    0.0    0.0    0.0  0.0  0.0    0.4   0   0
ssd14     0.0    0.0    0.0    0.0  0.0  0.0    0.4   0   0
ssd16     0.0    0.0    0.0    0.0  0.0  0.0    0.4   0   0
ssd18     0.0    0.0    0.0    0.0  0.0  0.0    0.4   0   0
ssd19     0.0    0.0    0.0    0.0  0.0  0.0    0.2   0   0
ssd20     0.0    0.0    0.0    0.0  0.0  0.0    0.3   0   0
ssd23     0.0    0.0    0.0    0.0  0.0  0.0    0.3   0   0
ssd24     0.0    0.0    0.0    0.0  0.0  0.0    0.3   0   0
ssd25     0.0    0.0    0.0    0.0  0.0  0.0    0.3   0   0
ssd26     0.0    0.0    0.0    0.0  0.0  0.0    0.3   0   0
ssd28     0.0    0.0    0.0    0.0  0.0  0.0    0.3   0   0
ssd30     0.0    0.0    0.0    0.0  0.0  0.0    0.4   0   0
                 extended device statistics
device    r/s    w/s   kr/s   kw/s wait actv  svc_t  %w  %b
sd1       0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
sd5       0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
sd6       0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
sd7       0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
sd8       0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd1      0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd3      0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd6      0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd10     0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd12     0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd14     0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd16     0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd18     0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd19     0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd20     0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd23     0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd24     0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd25     0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd26     0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd28     0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0
ssd30     0.0    0.0    0.0    0.0  0.0  0.0    0.0   0   0

I need to sum from ssd20 and ssd30 of second block in new line and sum from sd1 to sd8 in another line.
# 9  
Old 08-28-2012
This acts exactly as you have specified:
Code:
awk     'BEGIN {f[1,1]="ONE"; f[2,1]="TWO"; OFS="\t"}
        /^sd[1-8]/       {for (i=2;i<NF;i++) f[1,i]+=$i}
        /^ssd[23][0-9]/  {for (i=2;i<NF;i++) f[2,i]+=$i}
        $1=$1
        END {for (i=1;i<=2;i++) {printf "%s ",f[i,1]; for (j=2;j<=10;j++) printf "\t%3.1f", f[i,j]; print ""}}
        '

This User Gave Thanks to RudiC For This Post:
# 10  
Old 08-28-2012
OK, use "tail" and exclude first block and sum the specific column.
thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk printing output to new line

Hi I have a file profile.txt with the below input: {"atgUserId":"736f14c4-eda2-4531-9d40-9de4d6d1fb0f","firstName":"donna","lastName":"biehler","email":"schoolathome42@live.com","receiveEmail":"y es"}, {"atgUserId":"c3716baf-9bf8-42da-8a44-a13fff68d20f","firstName":"Gilberto... (6 Replies)
Discussion started by: ankur328
6 Replies

2. Shell Programming and Scripting

Print awk output in same line ,For loop

My code is something like below. #/bin/bash for i in `ps -ef | grep pmon | grep -v bash | grep -v grep | grep -v perl | grep -v asm | grep -v MGMT|awk '{print $1" "$8}'` do echo $i ORACLE_SID=`echo $line | awk '{print $2}'` USERNAME=`echo $line | awk '{print $1}'` done ============= But... (3 Replies)
Discussion started by: tapia
3 Replies

3. Shell Programming and Scripting

Output on one line using awk or sed

I have a file of 100,000 lines in the below format: answer.bed chr1 957570 957852 NOC2L chr1 976034 976270 PERM1 chr1 976542 976787 PERM1 I need to get each on one line and so far what I have tried doesn't seem to be working. Thank you... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. UNIX for Dummies Questions & Answers

awk output line by line

Hi all, New to the forum and somewhat of a Bash newbie so go easy. ;) I have some data in a tsv file, a sample of which looks like this (ignore what look like duplicates, in reality there are many more columns of data): SAMD11 NM_152486.2 intronic SAMD11 NM_152486.2 intronic... (2 Replies)
Discussion started by: winkleman
2 Replies

5. Shell Programming and Scripting

Reading ls -l output line by line awk the user name and su user to run commands

Using ksh on AIX what I am trying to do is to read the ls -l output from a file in a do while loop line by line. Extract the user name(3rd field) and the directory/file name(9th field) using awk and save them into variables. su -c to the user and change directory/file permisions to 777. Script I... (13 Replies)
Discussion started by: zubairom
13 Replies

6. Shell Programming and Scripting

How to sum multiple column output with awk ?

Hi Experts, I am trying to sum multiple columns and rows with awk , I want the sum of : 1] Horizontal Sum: (rows sum): 2] Vertical Sum: (Column's sum] details: # cat file1 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 40 31 32 33 34 35 36 37 38 39 70 41 42 43 44... (2 Replies)
Discussion started by: rveri
2 Replies

7. Shell Programming and Scripting

Need to have output of AWK array in one line

I have this code echo $logfile | awk ' {arr++; next} END { for (i in arr) {print i} }' that gives me this output result1 result2 result3 I try to figure out how to get it like this result1 result2 result3 (4 Replies)
Discussion started by: Jotne
4 Replies

8. Shell Programming and Scripting

[SOLVED] Awk one line to sum up a function

I need help with debugging an error in my awk script. I have a shell script with variable named U_new_i and want to pass it to awk for use in a summation. The original file have the following content. cat test.txt -2445.7132000000 -2444.9349000000 -2444.3295000000 -2443.1814000000 ... (0 Replies)
Discussion started by: Quantum_Dot
0 Replies

9. Shell Programming and Scripting

scripting/awk help : awk sum output is not comming in regular format. Pls advise.

Hi Experts, I am adding a column of numbers with awk , however not getting correct output: # awk '{sum+=$1} END {print sum}' datafile 2.15291e+06 How can I getthe output like : 2152910 Thank you.. # awk '{sum+=$1} END {print sum}' datafile 2.15079e+06 (3 Replies)
Discussion started by: rveri
3 Replies

10. Shell Programming and Scripting

awk help required to group output and print a part of group line and original line

Hi, Need awk help to group and print lines to format the output as shown below INPUT FORMAT set echo on set heading on set spool on /* SCHEMA1 */ CREATE TABLE T1; /* SCHEMA1 */ CREATE TABLE T2; /* SCHEMA1 */ CREATE TABLE T3; /* SCHEMA1 */ CREATE TABLE T4; /* SCHEMA1 */ CREATE TABLE T5;... (5 Replies)
Discussion started by: rajan_san
5 Replies
Login or Register to Ask a Question