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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Adding and Subtracting Variables

Reply to Message Icon

Name: Big_Z
Date: May 19, 2004 at 10:40:39 Pacific
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



Sponsored Link
Ads by Google

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

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

(( TotalB = (Total - TotalA) ))



0

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

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

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Adding and Subtracting Variables

Adding date to variable www.computing.net/answers/unix/adding-date-to-variable/7185.html

Create and validate variables in shell script www.computing.net/answers/unix/create-and-validate-variables-in-shell-script/1660.html

Script to add and subtract www.computing.net/answers/unix/script-to-add-and-subtract/8470.html