Awk or If/statement Calculation Problem

Awk or If/statement Calculation Problem
# 1
09-23-2012
Awk or If/statement Calculation Problem

returns:

what am i doing wrong here?

sometimes, when the numbers are in notation, i also get an error. how can i fix this?

i get this error:

i want to be able to compare any value to a set number.

like, if 1.51764e+06 is greater than whatever value is in a specific variable, do this or that.

any ideas?
 SkySmart View Public Profile for SkySmart Find all posts by SkySmart
# 2
09-23-2012
I am confused why you call this thread 'awk' when you're not using awk.

You didn't put a 'then', shell if needs those.

...but, as you discovered, shell does not support floating point. KSH is the only shell that does.

You can use awk instead, but this is expensive.

This User Gave Thanks to Corona688 For This Post:
 Corona688 View Public Profile for Corona688 Visit Corona688's homepage! Find all posts by Corona688
# 3
09-23-2012
Quote:
Originally Posted by Corona688
I am confused why you call this thread 'awk' when you're not using awk.

You didn't put a 'then', shell if needs those.

...but, as you discovered, shell does not support floating point. KSH is the only shell that does.

You can use awk instead, but this is expensive.

thank you for the response!

the script i'm working on is pretty huge. but here is the part i just need to modify to be able to support a floating point:

any one of these variables can have a floating point.

the script is written in bash.
 SkySmart View Public Profile for SkySmart Find all posts by SkySmart
# 4
09-23-2012
If any one of those variables can have a floating point, you can't use ==. An infintesimal difference or even same number, different representation could make them not equal. How accurate do you want the comparison?
 Corona688 View Public Profile for Corona688 Visit Corona688's homepage! Find all posts by Corona688
# 5
09-24-2012
Quote:
Originally Posted by Corona688
If any one of those variables can have a floating point, you can't use ==. An infintesimal difference or even same number, different representation could make them not equal. How accurate do you want the comparison?
this is what i ended up doing, but i'm not sure if it's doing what i want it to:

 SkySmart View Public Profile for SkySmart Find all posts by SkySmart
# 6
09-24-2012
Quote:
Originally Posted by SkySmart
can we use above highlighted directly..?

i think this should be

 pamu View Public Profile for pamu Find all posts by pamu
# 7
09-24-2012
Quote:
Originally Posted by pamu
can we use above highlighted directly..?
Yes, this is how if is meant to be used. It checks the return status of the command given.

If in doubt, remember, [ is a command.

Usually a shell builtin, these days, but the command still exists.
This User Gave Thanks to Corona688 For This Post:
 Corona688 View Public Profile for Corona688 Visit Corona688's homepage! Find all posts by Corona688

awk calculation with zero as N/A

In the below awk, I am trying to calculate percent for a given id. It is very close the problem is when the # being used in the calculation is zero. I am not sure how to code this condition into the awk as it happens frequently. The portion in italics was an attempt but that lead to an error. Thank...

awk split and awk calculation in the same command

I am trying to run the awk below. My question is when I split the input, then run anotherawk to perform a calculation using that splitas the input there are no issues. When I try to combine them the output is not correct, is the split not working or did I do it wrong? Thank you :). input ...

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE...

Awk/sed problem to write Db insertion statement

Hi There, I am trying to load data from a csv file into a DB during our DB migration phase. I am successfully able export all data into a .csv file but those have to rewritten in terms insert statement which will allow for further population of same data in different DB My exiting csv record...

Need to remove leading space from awk statement space from calculation

I created a awk state to calculate the number of success however when the query runs it has a leading zero. Any ideas on how to remove the leading zero from the calculation? Here is my query: cat myfile.log | grep | awk '{print \$2,\$3,\$7,\$11,\$15,\$19,\$23,\$27,\$31,\$35(\$19/\$15*100)}' 02:00:00...

Decimal number calculation problem

I have a below snippet of code from my perl script and its causing a problem when the output of \$lTAX is 0 (zero) its getting displayed as -0.00. I want output to be 0 not -0.00. Any help would be appreciated. #!/usr/bin/perl my \$lTotA = 50.94; my \$lVatA = 8.49; my \$lAllocD; my \$lAdjNr =...

Problem in echo value after some calculation

val=21 total=3250 echo "`echo "scale=2; \$val*100/\$total" | bc`" Output: .64 How do i show the output become "0.64" instead of ".64" ?? Someone can help?

Problem with awk and if statement

Hi, I have a task where i need to compare columns of two files. First file is \$REG_InputFileName: "UPDATE","1010021126","1-01-01","USD" "UPDATE","1013000101","1-01-01","THB" "UPDATE","1013010107","1-01-01","THB" "UPDATE","1110011122","1-01-01","USD"...

awk calculation problem

I have a list of coordinate data, sampled below. 54555209 784672723 I want it as: 545552.09 7846727.23 Below is my script: BEGIN {FS= " "; OFS= ","} {print \$1*.01,\$2*.01} This is my outcome: 5.5e7 7.8e8 How do I tell awk that I want to keep all the digits instead of outputting...

Problem with float calculation and awk

Hi All, can some body help me to script the below logic. Basically am facing problem with float calculation. Also i need this to be done inside a single awk. I tried lot of tuning but still nothing is getting displayed, nor any errors param=50 value=19.23 for(i=0;i<4;i++) {...