## How to sum the value with negative values?

How to sum the value with negative values?
# 1
11-16-2016
How to sum the value with negative values?

Hi Gurus,

I have requirement need to sum the value, the logic is if the value is negative then time -1, I tried below two ways. one is failed, another one doesn't work.

 ken6503 View Public Profile for ken6503 Find all posts by ken6503
# 2
11-16-2016

You need to declare/define the abs function if you want to use it.
This User Gave Thanks to RudiC For This Post:
 RudiC View Public Profile for RudiC Find all posts by RudiC
# 3
11-16-2016
This User Gave Thanks to balajesuri For This Post:
 balajesuri View Public Profile for balajesuri Find all posts by balajesuri
# 4
11-16-2016
Hello ken6503,

Could you please try following and let me know if this helps you.
EDIT: Adding one more little modified version of above solution.
Thanks,
R. Singh

Last edited by RavinderSingh13; 11-16-2016 at 02:18 PM.. Reason: Added one more solution successfully now.
This User Gave Thanks to RavinderSingh13 For This Post:
 RavinderSingh13 View Public Profile for RavinderSingh13 Find all posts by RavinderSingh13
# 5
11-16-2016
As always, thanks all of you give me such great idea.

thanks again.
 ken6503 View Public Profile for ken6503 Find all posts by ken6503

## Conavert negative values to Zeros

Can anyone please assist me? Please find the attached input and output file for ur reference. a)Incase if i get negative value (ex:-000100) in the 11th column then i have to convert the value to 0000000(7 zeros-length is 7) and then print the entire record. b)Incase if there is no...

## Awk+colpos+negative if for 20 values

Hi All, i have 20 Obligors when ever i dont find all of them on particular row/line from each in put i need to print it in different file. using below command but it is not working please help at earliest. Steps: set -A FILENAME \$( cat...

## replacing negative values in a column with zero

Hi, i need help on replacing negative values in a column with 0. any quick fix on this? thanks much. for instance, input: 1 2.3 -0.4 -25 12 13 45 -12 desired output 1 2.3 0 0 12 13 45

## error- multiplying negative decimal values

a=10.02 pattern=-11.01 b=\$(echo | awk '{ print \$a*\$pattern}') echo \$b its not working even ALso tried `expr \$a \* \$pattern` No LUCK

## Snmp Disk Problem = Negative Values

Ok, so i monitor disk space on remote machines using snmp. Works great for me. But whenever a particular partition happens to have Terabytes of data, snmp starts reporting negative values. Can someone please tell me how to get around this problem? The AllocationUnit is 512 bytes. Weird...

## Find Where Values Change From Positive To Negative and viceversa

Hi all, I have a file that looks like shown below. I want to find places where the value in column 2 change from negative to positive and vice versa and return the value on column 1 at that point. I wonder if this is possible in shell script or awk .. please help! Here is the original data ...

## Sorting positive and negative values

Hello, I have a list like this : 1 2 -4 0 -3 -7 5 6 etc. Is there a way to remove all the positive values and print only the negative values, without using grep, sed or awk? Thanks, Prasanna

## printf in bash shell not printing negative values

hi i am using printf in a script and it is not printing negative values..i have to use printf to get rid of the newline..here is my code: fin=`echo \$a - \$b | bc` printf "\${fin}," >> test these statements are in a loop. here is what i get when i try to subtract 4 from 8: ./scr1: line...

## Help in adding positive & negative values in a column

Hi Gurus, In my file I have an amount field from position 74 to 87, which contains values starting with '+' as well as '-'. I want to add all positive values in a varible called "CREDIT" and all negative values in a variable "DEBIT". I know, we can use grep to identify values with positive and...