Script to find out the sum of output on the screen


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to find out the sum of output on the screen
# 1  
Old 12-08-2013
Script to find out the sum of output on the screen

Hi,
I am new to scripting.I am using redhat linux 6.I am just finding a way to summing up the output displayed as below.It will help me a lot since we used to get this kind of output every now and then.

I am pasting here the output .What is required is this o/p needs to be summed up and final value should be displayed.

for example:
Code:
# lsvdisk | grep -vi cap | awk '{print $8}'
1.57TB
1.57TB
2.00TB
70.00GB
90.00GB
70.00GB
70.00GB

output should be displayed like:few of them are TB and few of them are in GB.
might be a seperate output for TB and GB is also fine.
300 GB and 5 TB.
Here i have pasted a sample.But in real time i used to get around 50 to 60 lines of output.
Appreciate your help on this.I am just finding a way from my end too.Advance thanks for your replies

Last edited by Scrutinizer; 12-08-2013 at 12:59 PM.. Reason: code tags instead of icode
# 2  
Old 12-08-2013
Try something like:
Code:
awk '{t+=$8/($8~/GB/?1024:1)} END{print t, "TB"}'

It could also be further combined with the grep statement (and further refined if there are also MB or EB, for example)
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 12-08-2013
Quote:
Originally Posted by muraliinfy04
might be a seperate output for TB and GB is also fine.
Code:
lsvdisk | awk '
        !/[Cc][Aa][Pp]/ {
                match ( $8, /[A-Z]*$/, A )
                R[A[0]] += $8
        }
        END {
                for ( k in R )
                        print R[k], k
        }
'

This User Gave Thanks to Yoda For This Post:
# 4  
Old 12-09-2013
Thanks alot.It's awesome.It is working as expected.
Once again very very thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need output of script on screen and file with correct return status of the called script.

Hi, I am trying to capture logs of the script in the file as well as on the screen. I have used exec and tee command for this. While using exec command I am getting the correct output in the file but, script output is not getting displayed on the screen as it get executed. Below is my sample... (14 Replies)
Discussion started by: Prathmesh
14 Replies

2. Shell Programming and Scripting

Shell script to find the sum of argument passed to the script

I want to make a script which takes the number of argument, add those argument and gives output to the user, but I am not getting through... Script that i am using is below : #!/bin/bash sum=0 for i in $@ do sum=$sum+$1 echo $sum shift done I am executing the script as... (3 Replies)
Discussion started by: mukulverma2408
3 Replies

3. Shell Programming and Scripting

Slow down output from dhclient-script to screen

Hi I know the basic about script and sleep processes. However this is more tricky: I would like to run sh -x /sbin/dhclient-script and slow down the output of the script as a whole. How would you do it? I would like to delay output on the screen with 1 second for every line for the output... (3 Replies)
Discussion started by: medium_linux
3 Replies

4. Shell Programming and Scripting

Help supressing spool output from screen when calling sqlplus from script

I'm calling an embedded sql from my shell script file. This sql does simple task of spooling out the contents of the table (see below my sample code) into a spool file that I specify. So far so good, but the problem is that the output is also displayed on screen which I do NOT want. How can I... (3 Replies)
Discussion started by: MxC
3 Replies

5. Homework & Coursework Questions

Help with shell script to find sum of first n numbers of Fibonacci series

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Shell script to find sum of first n numbers of Fibonacci series 2. Relevant commands, code, scripts,... (0 Replies)
Discussion started by: Kshitija
0 Replies

6. Shell Programming and Scripting

Shell script to find the sum of first n Fibonacci numbers

pls give me the solution for this i need it for my exam pls pls pls Shell script to find the sum of first n Fibonacci numbers (1 Reply)
Discussion started by: Kshitija
1 Replies

7. Shell Programming and Scripting

Perl script to find particular field and sum it

Hi, I have a file with format a b c d e 1 1 2 2 2 1 2 2 2 3 1 1 1 1 2 1 1 1 1 4 1 1 1 1 6 in column e i want to find all similar fields ( with perl script )and sum it how many are there for instance in format above. 2 - 2 times 4 - 1 time 6 - 1 time what i use is ... (14 Replies)
Discussion started by: Learnerabc
14 Replies

8. Shell Programming and Scripting

To record screen output using "script" command

I am trying to capture the session of a particular user id, by using the "script" command, by adding the "script" command to the .profile of that user id. Now, when I have to exit the session, I am having to give 2 exits - one for the script command, and the other to log out of the session. Is... (2 Replies)
Discussion started by: ggayathri
2 Replies

9. UNIX for Dummies Questions & Answers

how to print script output to screen and file

Hi all, I have a script that bulk loads thousands of lines of data. I need to log the output during the execution of the script. I know I can redirect (">") the output to a file; however, I want the output going to both the screen and the log file. I thought I could use pipe to pipe the... (10 Replies)
Discussion started by: orahi001
10 Replies

10. Shell Programming and Scripting

Q: Recording shell script screen output using "script" command ?

Hello, I need to capture everything showed on a screen by a shell script which needs user interaction. The shell script performs commads such as rsh so normal redirection to a file does not work. I know there is a special unix command call "script" which records screen session but the... (4 Replies)
Discussion started by: lalfonso.gomez
4 Replies
Login or Register to Ask a Question