02-03-2013
For Loop & SUM
HTML Code:
pcmpath query device |awk 'BEGIN{print "DEVICE NAME\tSERIAL"} /DEVICE NAME/ {printf "%s\t", $5; getline; print substr($2, length($2)-3)}'
This script returns output like below to pull out "DEVICE NAME SERIAL".
HTML Code:
......
hdisk28 110B
hdisk29 1112
hdisk30 1115
hdisk31 1116
hdisk32 1128
hdisk33 112D
hdisk34 112E
hdisk35 1147
hdisk36 1148
hdisk37 1149
hdisk38 114A
hdisk39 114B
hdisk40 114C
hdisk41 114D
hdisk42 114E
hdisk43 116B
hdisk44 116C
hdisk45 116D
hdisk46 116E
.....
The script below is to pull out the disk size.
HTML Code:
for disk in `pcmpath query device |awk 'BEGIN{print "DEVICE NAME\tSERIAL"} /DEVICE NAME/ {printf "%s\t", $5; getline; print substr($2, length($2)-3)}' |awk '{print$1}'`
do
printf "%s\t" $disk; bootinfo -s $disk
done
But, what I need to have is the sum of hdisks with the output:
HTML Code:
List of the output first:
DEVICE NAME SERIAL SIZE
hdisk28 110B 36864
hdisk29 1112 36864
hdisk30 1115 36864
hdisk31 1116 24576
hdisk32 1116 16384
......
and then add them up as Sub-Total and Grand Total followed by:
DISK SUMMARY in MB
SIZE: 36864 NUMBER OF DISKS: 3 SUB-TOTAL: 110592
SIZE: 24576 NUMBER OF DISKS: 1 SUB-TOTAL: 24576
SIZE: 16384 NUMBER OF DISKS: 1 SUB-TOTAL: 16384
....
GRAND TOTAL ======================== xxxxxxxx
Please let me me know how to get the disk size per each disk size and disk summary (SIZE: NUMBER OF DISKS: SUB-TOTAL & GRAND TOTAL)
9 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hello everyone!!
I have to write a script in unix that reads a file which is in the format:
1%blabla%30
2%blabla2%50
1%blabla3%40
2%blabla4%10
and produce the total quantities of 1 and 2: "1 = 70 2 = 60"
I am taught basic unix commands, so I must keep it simple, how can i do this using... (7 Replies)
Discussion started by: questionmaker25
7 Replies
2. Shell Programming and Scripting
Hi,
I am trying to extracting the sum of all varibles listed in a file.
The code is as follows
##### FILE1 ########
Value1:2
Value2:2
Value3:6
Value4:5
##### shell script ######
#!/bin/sh
total=0 (2 Replies)
Discussion started by: eagercyber
2 Replies
3. Shell Programming and Scripting
Hi All,
I have a file abc.txt with 3 fileds. Field 3 contains amount. Also at the end of file there is a Footer record, which contains total amount.
I need to calculate total sum of these fields & need to compare it with footer record. I have serched in thi site, many has asked this... (7 Replies)
Discussion started by: Amit.Sagpariya
7 Replies
4. Shell Programming and Scripting
Hi,
I am unable sum of each column in the loop usng awk command.
Awk is not allowing the parameters in the command.
i am facing the below error.
awk: 0602-562 Field $() is not correct.
Source file
abc.txt
100,200,300,400,500,600,700,800,900
101,201,301,401,501,601,701,801,901
... (1 Reply)
Discussion started by: number10
1 Replies
5. Shell Programming and Scripting
Hi,
I have a hash which is to be populated by reading data lines from a flat file. I am supposed to read fields 1-5 from the file and load them on to the hash such that fields 1-4 are going to be the hash key-set and field 5 is the hash value.
Field 5 is a monetary amount and is supposed... (1 Reply)
Discussion started by: sinpeak
1 Replies
6. Shell Programming and Scripting
Hi All,
I got stuck up with shell script where i use awk. The scenario which i am working on is as below.
I have a file text.txt with contents
COL1 COL2 COL3 COL4
1 A 500 200
1 B 500 300
2 A 290 150
2 B 290 140
3 C 100 100
I could able to sum col 3 and col4 based on col1 using... (1 Reply)
Discussion started by: imsularif
1 Replies
7. Shell Programming and Scripting
Hi
i have to calculate some numbers, column by column.
Herfore i used a for-loop..
for i in {4..26};do awk -F"," '{x'$i'+=$'$i'}END{print '$i'"\t" x'$i'}' file.tmp;done
----- printout -----
4 660905240
5 71205272
6 8.26169e+07
7 8.85961e+07
8 8.60936e+07
9 7.42238e+07
10 5.6051e+07... (7 Replies)
Discussion started by: IMPe
7 Replies
8. Post Here to Contact Site Administrators and Moderators
i want code in awk with loop to get the sum
* is delimiter in file
TOTAL_AMOUNT=SUM(CLP04)
suppose there are 12 CLP04 segment in my file i want to add upto 5 CLP04 then print next line after BPR segment after calculate the total amount
CLP04 means
ex
... (5 Replies)
Discussion started by: MOHANP12
5 Replies
9. Shell Programming and Scripting
Hi all,
I have one host i need to run in loop to check the capacity from different frame and get the output to one file and sum it and convert to TB
this is Code
#!/bin/ksh
DATE=`date '+%d%m%y'`
for f in `cat /home/esx-capacity/esx-host.txt`
do
for g in `cat /home/esx-capacity/frame`... (10 Replies)
Discussion started by: ranjancom2000
10 Replies