Computing.Net > Forums > Unix > Adding and Subtracting Variables

Adding and Subtracting Variables

Reply to Message Icon

Original Message
Name: Big_Z
Date: May 19, 2004 at 10:40:39 Pacific
Subject: Adding and Subtracting Variables
OS: AIX 5.1
CPU/Ram: 1
Comment:

Hello,

I have a script in which I need to subtract the value of one variable from another.

Here is an example of what I am doing:

Total=$(grep -c XXXX filename.txt)
TotalA=$(grep -c -E "AA|BB" filename.txt)
TotalB= ????

I want to set the variable TotalB to subtract TotalA from Total. Each variable will be a number.. Do I also need to define as integer?

Thanks for any help on this.

Big Z


Report Offensive Message For Removal


Response Number 1
Name: thepubba
Date: May 19, 2004 at 12:26:59 Pacific
Reply: (edit)

As long as you are not doing floating point, this should work:

(( TotalB = (Total - TotalA) ))



Report Offensive Follow Up For Removal

Response Number 2
Name: Dlonra
Date: May 19, 2004 at 18:39:10 Pacific
Reply: (edit)

TotalB=$(($Total - $TotalA)) # bash

or
TotalB=$(( $(grep -c XXXX filename.txt) - $(grep -c -E "AA|BB" filename.txt) ))


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Adding and Subtracting Variables

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge