Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Summing results resident in a var

Status
Not open for further replies.

sumncguy

IS-IT--Management
May 22, 2006
118
US


fl1psiz=`$sn $ip 1.3.6.1.4.1.9.9.10.1.1.4.1.1.4 | sed 's/.*GER: //' | tr '\012' ' '`

The line above returns the line shown below. I want to add these values together.

8388608 8388608

Whats the best way to do this ?
 
Code:
fl1psiz=`$sn $ip 1.3.6.1.4.1.9.9.10.1.1.4.1.1.4 | sed 's/.*GER: //' | tr '\012' ' '` | while read one two
do
  expr $one + $two 
done

Ceci n'est pas une signature
Columb Healy
 
I think Columb meant:

Code:
fl1psiz=`$sn $ip 1.3.6.1.4.1.9.9.10.1.1.4.1.1.4 | sed 's/.*GER: //' | tr '\012' ' '`
echo $fl1psiz | while read one two
do
  expr $one + $two
done

Annihilannic.
 
Or perhaps this ?
fl1psiz=`$sn $ip 1.3.6.1.4.1.9.9.10.1.1.4.1.1.4 | awk '{sub(/.*GER: /,"");t+=$0}END{print t}'`

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

Thanks works great.

One other thing that I forgot to ask was ...

How do I change (round) 16777216 to the nearest Megabit ?
ie 16M or even 17M which is plain enough.

Also, is there a decent online resource for ksh and mathmatics ? I have the Oreilly Ksh Scripting and it doesnt go into this kind of thing ... could have missed it I suppose.

Thanks again.

 
perhaps, the home of Mr. Korn himself. And of course the ksh man page. For most things you can put a simple mathematical expression between $(( and )), e.g.

[tt]$ echo $(( 16777216 / 1024 / 1024 ))
16
$[/tt]

You can just divide by 1024 twice to get to Megabits.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top