# How to eliminate inf value in AWK

**URL:** <https://community.unix.com/t/how-to-eliminate-inf-value-in-awk/178406>\
**Category:** Shell Programming and Scripting\
**Created:** [December 3, 2007, 1:24am UTC](https://community.unix.com/t/how-to-eliminate-inf-value-in-awk/178406 "2007-12-03T01:24:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahjiefreak](https://community.unix.com/letter_avatar/ahjiefreak/32/5_5575768a8748004e209b776fc1b2916d.png) [@ahjiefreak](https://community.unix.com/u/ahjiefreak)\
**Post date:** [December 3, 2007, 1:24am UTC](https://community.unix.com/t/how-to-eliminate-inf-value-in-awk/178406/1 "2007-12-03T01:24:51Z")

</div>

Hi,

I have the calculations which return me infinity (inf), -inf, other very larger number when I printed them out.

I did try to insert some control condition not to print these out if the above condition is met. The code I implemented is something like:-

for (i=0;i\<=1000;i++){  
if(count [i]!="inf"|| count [i]!="-inf" ||count[i]!\<0 ||count[i]!\>0){  
printf("%.2f %0d\n", count[i], i);}}  
}  
However the above doesnt work. It still prints out these condition. Anyone here know what is the most likely mistakes I made here.

Thanks.

-Jason

---

<div class="post-metadata">

**Author:** ![Smiling\_Dragon](https://community.unix.com/user_avatar/community.unix.com/smiling_dragon/32/722_2.png) [@Smiling\_Dragon](https://community.unix.com/u/Smiling_Dragon)\
**Post date:** [December 3, 2007, 3:32pm UTC](https://community.unix.com/t/how-to-eliminate-inf-value-in-awk/178406/2 "2007-12-03T15:32:29Z")

</div>

It looks like a logic error here. You've written a tautology (if "it's not inf" or "it's not -inf" then print)  
Try using && instead of || to get it to only print if all of the predecates match (if "it's not inf" and "it's not -inf" then print)

---

<div class="post-metadata">

**Author:** ![ahjiefreak](https://community.unix.com/letter_avatar/ahjiefreak/32/5_5575768a8748004e209b776fc1b2916d.png) [@ahjiefreak](https://community.unix.com/u/ahjiefreak)\
**Post date:** [December 3, 2007, 6:37pm UTC](https://community.unix.com/t/how-to-eliminate-inf-value-in-awk/178406/3 "2007-12-03T18:37:30Z")

</div>

Hi,

At least, I managed to get rid of INF using this tautology suggested. Can I know the exact reason of why the logic is wrong. Because ultimately I am just comparing the "INF" or "-INF" which is seen in the file, if these appear, it wont print out the information related to "INF" or "-INF".

Besides, one thing I found out that by changing the data type from "f" (float) to "g", the INF and -INF data are eliminated as well.

Please advise. Thanks.

-Jason

---

<div class="post-metadata">

**Author:** ![Smiling\_Dragon](https://community.unix.com/user_avatar/community.unix.com/smiling_dragon/32/722_2.png) [@Smiling\_Dragon](https://community.unix.com/u/Smiling_Dragon)\
**Post date:** [December 3, 2007, 9:58pm UTC](https://community.unix.com/t/how-to-eliminate-inf-value-in-awk/178406/4 "2007-12-03T21:58:39Z")

</div>

A tautology means a statement that will always evaluate to true - it's like a useless comment. In programming, it's always a mistake to have a tautology as it's wasted cycles.

The regular expression you are using (count [i]!="inf"|| count [i]!="-inf" ||count[i]!\<0 ||count[i]!\>0) is one big tautology.

Look at it this way, you want it to print if the value is not equal to "info" and not equal to "-inf".  
I can't figure out what you are looking for with the compares with 0 you are doing. Your current script will print if the value is not less than 0 or not greater than 0 (which is the same as saying it will always print).
