Sponsored Content
Top Forums Shell Programming and Scripting Division by zero attempted error during linear conversion of values between 0.25 to 1 Post 303000988 by sammy777888 on Monday 24th of July 2017 06:42:14 PM
Old 07-24-2017
Division by zero attempted error during linear conversion of values between 0.25 to 1

I want to implement the below formula with awk oneliner
Code:
new_value = ((old_value - old_min) / (old_max - old_min) ) * (new_max - new_min) + new_min

I want to pass the value of old_min and old_min as variable. Here is what I did for this
Code:
old_min=$(awk 'BEGIN{a=100000000000}{if ($10<0+a) a=$10} END{print a}' temp11)
old_max=$(awk 'BEGIN{a=   0}{if ($10>0+a) a=$10} END{print a}' temp11)
echo $old_min
4828
echo $old_max
449064

Then I run the command, which gives the error message
Code:
awk '{ print $0, (($10 - $old_min)/($old_max - $old_min)) * ((1 - 0.25) + 0.25)}' temp11
awk: cmd. line:1: (FILENAME=temp11 FNR=1) fatal: division by zero attempted

Then I tried simply which worked fine
Code:
awk '{ print $0, (($10 - 4828)/(449064 - 4828)) * (1 - 0.25) + 0.25}' temp11

but I need to assign $old_min and $old_max dynamically as my script.sh run it inside the loop. Thanks
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Displaying fraction values after arithmetic division

Hi , I have the following line of code : new=$(($old/300)) But if the value is less than 300 i get the answer as "0" . How will i get the fraction values ? sars (2 Replies)
Discussion started by: sars
2 Replies

2. Shell Programming and Scripting

division by 0 error

Hi, I am writing a script that among other things will be checking for various files on mount points. One of the conditions is that unless the server has failed over the df command will show root ( / ). If when checking the files the script comes across /, I want it to skip it, otherwise to... (2 Replies)
Discussion started by: cat55
2 Replies

3. Shell Programming and Scripting

error "awk: (FILENAME=- FNR=23) fatal: division by zero attempted"

Hi , I have file : after i run this command : there are error can we print blank line if output error ?? thanks.. ^^ (4 Replies)
Discussion started by: justbow
4 Replies

4. Shell Programming and Scripting

Division by zero error message in AWK

How can I modify my awk code to get rid of the divion by zero error message? If I run the script without an input file, it should return error message "Input file missing" but not divison by zero. Code: #!/bin/nawk -f BEGIN { if (NR == 0) {print "Input file... (4 Replies)
Discussion started by: Pauline mugisha
4 Replies

5. Shell Programming and Scripting

awk error message: division by zero attempted

Hi, I'm executing unixbench tool v4.1 on an embedded system and I'm getting these error messages: Execl Throughput 1 2 3awk: /unixbench/unixbench-4.1.0/pgms/loops.awk:38: (FILENAME=- FNR=4) fatal: division by zero attempted Pipe Throughput 1 2 3 4 5 6 7 8 9 10awk:... (3 Replies)
Discussion started by: rogelio
3 Replies

6. Shell Programming and Scripting

awk division error - 0

input 0 0 9820373 2069 0 0 11485482 awk '{print ($1/$3) / ($4/$7)}' input error Is there any way to fix this problem ? (25 Replies)
Discussion started by: quincyjones
25 Replies

7. Shell Programming and Scripting

Awk: cmd. line:1: fatal: division by zero attempted

when i try the snippet in the console its working fine: ps awwwux | grep php-fpm | grep -v grep | grep -v master | awk '{total_mem = $6 * 1024 + total_mem; total_proc++} END{printf("%d\n", total_mem / total_proc)}' output: but when i try the bash script: #!/bin/sh # -*- sh -*- #... (3 Replies)
Discussion started by: danieloooo
3 Replies

8. Shell Programming and Scripting

awk fatal:division by zero attempted bypass with a condtion

Hi Friends, My input chr1 100 200 1234E-02 0.01 0.05 10 chr1 100 200 14E-11 0.11 0.50 1 chr1 100 200 134E-22 0.00 0.65 111 My command awk '{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$13}' input | awk '{v=($5/$6); print $0"\t"v}' OFS="\t" | awk '{$8=(log($8)/log(2)); print $0}'... (4 Replies)
Discussion started by: jacobs.smith
4 Replies

9. Shell Programming and Scripting

awk - continue when encountered division error

Hello, How can I add a logic to awk to tell it to print 0 when encountering a division by zero attempted? Below is the code. Everything in the code works fine except the piece that I want to calculate read/write IO size. I take the kbr / rs and kbw / ws. There are times when the iostat data... (5 Replies)
Discussion started by: tommyd
5 Replies

10. UNIX for Beginners Questions & Answers

Fatal division by zero attempted

Hello. I'm writing an awk script that looks at a .csv file and calculates the weighted grade based on the scores and categories in the file. I keep getting a fatal division by zero attempted error and I know what it means but I've been looking over the code for awhile and am not sure what is... (4 Replies)
Discussion started by: Eric7giants
4 Replies
WINCACHE_UCACHE_CAS(3)							 1						    WINCACHE_UCACHE_CAS(3)

wincache_ucache_cas - Compares the variable with old value and assigns new value to it

SYNOPSIS
bool wincache_ucache_cas (string $key, int $old_value, int $new_value) DESCRIPTION
Compares the variable associated with the $key with $old_value and if it matches then assigns the $new_value to it. PARAMETERS
o $key - The $key that is used to store the variable in the cache. $key is case sensitive. o $old_value - Old value of the variable pointed by $key in the user cache. The value should be of type long, otherwise the function returns FALSE. o $new_value - New value which will get assigned to variable pointer by $key if a match is found. The value should be of type long, otherwise the function returns FALSE. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 Using wincache_ucache_cas(3) <?php wincache_ucache_set('counter', 2922); var_dump(wincache_ucache_cas('counter', 2922, 1)); var_dump(wincache_ucache_get('counter')); ?> The above example will output: bool(true) int(1) SEE ALSO
wincache_ucache_inc(3), wincache_ucache_dec(3). PHP Documentation Group WINCACHE_UCACHE_CAS(3)
All times are GMT -4. The time now is 03:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy