#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    1
    Rep Power
    0

    Maths, Variables and outputs.


    Hey,

    Im trying to write a sciript that runs a shell command, then adds to of the columns and then minus that from another column.

    ie

    Code:
    sar -r | awk '{print $1, $2, $3, $4, $7}'
    this is the command, how would the script then add $4 and $7 and minus that from $3??

    It would then diaplays the answer next to $1 and $2. Ive been looking the expr to do the maths, but dont sure how to do this is variables etc..
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    /dev/null
    Posts
    163
    Rep Power
    19
    awk can do the math for you:
    Code:
    awk '{print $1, $2, $4+$7-$3}'
    By the way, what is this question doing in the python forum???

IMN logo majestic logo threadwatch logo seochat tools logo