That is odd, though I'm sure there's a perfectly reasonable explanation!
Have you made any efforts to debug the code?
i.e. it would be helpful if you showed where the variables new_price and MIN_PRICE (not the same as min_price!) are declared and set, as well as printing their values before the offending print statement.
I am trying to compare two negative numbers using awk on linux.But it is giving me wrong result.Same code is working perfectly on solaris.
e.g If I try to compare -1.32(new_price) and -500(min_price) using "<" operator, output is 1 i.e true.
Where am I going wrong?
Thanks for your help in advance.
The most obvious explanation is that your solaris awk implementation, whatever it is, is performing a numerical comparison, while the linux awk implementation, whatever it is, is performing a string comparison (where -1.32 is indeed less, appears before -500 in a lexicographical sort).
To know which is correct (at least with respect to POSIX) would require seeing all of your code, which you neglected to post.
Add another +0 to the other operand to force numerical comparison, or, again, show us the entire script.
Curious, I tried this:
with every awk at my disposal and could not reproduce this. I did notice that you used MIN_PRICE in your script and min_price in your text about the value that you assigned to it. Could it be there is a mismatch (uppercase/lowercase) and therefore MIN_PRICE=0 would evaluate to 1
Yes I did try to debug by printing values of variable and those were printing correct values. And I was using NEW_PRICE everywhere. Sorry for confusion created by mentioning new_price in my post.
My problem is now resolved, after I have added +0 to another operand i.e NEW_PRICE.
Hi ALL,
I am having semi column separated file as below. I am having negative values for the records starting with 11095. How can I convert that positive number
I tried this below seems not working
sed 's/ \(*\)$/ -\1/;t;s/\(.*\)-/\1/ myfile
myfile... (6 Replies)
I am using a small script to divide some numbers in a given file and display the output in another file. I am getting the following error
basename: invalid option -- '5'
Try `basename --help' for more information.
(standard_in) 1: syntax error
The script is :
#!/bin/bash
for i in `cat... (4 Replies)
Hello, I am trying to write a bash script which will give me the most negative number. Here is an example input:
Ce 3.7729752124 -4.9505731588 -4.1061257680
Ce -6.9156611391 -0.5991784762 7.3051893138
Ce 7.6489739875 0.3513020731 ... (6 Replies)
Hello all,
I'm new to the forums and hope to be able to contribute something useful in the future; however I must admit that what has prompted me to join is the fact that currently I need help with something that has me at the end of my tether.
I have a PDB (Protein Data Bank) file which I... (13 Replies)
Hi All,
Just faced an interesting thing in HP-UX. I was dividing 2955334616 / 2 by using echo `expr 2955334616 / 2` , and this ofcourse which expects 1477667308 to be returned. But I am getting -669816340 and I am :wall: how exactly this is possible. It is not one of the compliments (Ones or... (4 Replies)
Hi, does anyone know how to ignore whether a number is negative in a script. E.g. if I have a variable that contains -1200, how do I ignore the minus sign? (1 Reply)
Hi,
I want to search for a return code of -3. Using grep "-3" *.* is giving a syntax error. Please suggest as to how can we search for this pattern using grep.
Thanks,
Krishna (2 Replies)
hi people,
I have a function which I am passing a stream which is basically postfix notation
if(isdigit(in.peek()))
{
in >> number;
nums.push(number);
}
else if (strchr("+-*/", in.peek( )) != NULL)
{
in >> symbol;
do_operation(symbol, nums, okay);
}
... (1 Reply)