Operating System - HP-UX
1830938 Members
1720 Online
110017 Solutions
New Discussion

How do I add results of wc -l

 
SOLVED
Go to solution
Paul Middleton
Frequent Advisor

How do I add results of wc -l

This is really dumb, but my brain hit a bad sector and I can't remember how to do this.
.
I have a short program to see how many power supplies are in a Nike. I use cstm and put results in a file. From the file is use a simple instruction -
psa=$(cat file|grep -c "VSC A: OK"|wc -l)
.
when I'm done looking for VSC A, B, C - I'm trying to get a total number of power supplies, since the customer have several Mod 20 units.
I've tried several commands to try and total the power supplies, but the output keeps coming back as "+1+1+1 etc".
Does anyone know a simple way to add $psa $psb and $psc to get a total?
.
I'm very generous with the points. Promise.
.
Regards,
Paul Middleton
Dilligad - Do I Look Like I Give A Damn
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: How do I add results of wc -l

You're making this too hard. The POSIX (and Korn) shell have built in integer math.

viz

X=$((${A} + ${B} + ${C}))
or
X=$((${A} * 3 + 7))

You also have the ability to nest using ()'s. the key is
$(( )) -- it's equivalent to the let statement but is much cleaner.

If it ain't broke, I can fix that.
Jeff Schussele
Honored Contributor

Re: How do I add results of wc -l

Hi Paul,

Many ways to do it - here's one

(($total=$psa+$psb+$psc))

$total will now contain the sum.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Jeff Schussele
Honored Contributor

Re: How do I add results of wc -l

Sorry....should be total NOT $total...fat fingered that one

Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Tony Contratto
Respected Contributor

Re: How do I add results of wc -l

Hi Paul,


# cat tmp.sh
#!/usr/bin/ksh

psa=2
psb=3
psc=4

echo $(( $psa + $psb + $psc ))

# ./tmp.sh
9


Hope this helps...
Tony
got root?
Paul Middleton
Frequent Advisor

Re: How do I add results of wc -l

Thanks for the information. Sometimes I make the problem harder than it is.
After 28 years in the field with hardware repairs, going into a supervisor position and working with HP-UX scripts is harder than I thought.
.
Wait a minute - if I had thought about it, I wouldn't be doing it.
.
Regards, and thanks again,
Paul Middleton
Dilligad - Do I Look Like I Give A Damn