How to eliminate inf value in AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to eliminate inf value in AWK
# 1  
Old 12-03-2007
How to eliminate inf value in AWK

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
# 2  
Old 12-03-2007
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)
# 3  
Old 12-03-2007
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
# 4  
Old 12-03-2007
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).
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Eliminate comma on Field

Hi All, Seeking for your assistance on my problem below: What i did was extract the records from database and change the extension name to .csv. My problem is there is a records contains comma between records if i opened it in excel it will generate the comma as new field(please see below... (6 Replies)
Discussion started by: znesotomayor
6 Replies

2. Shell Programming and Scripting

Need help to eliminate the records

Hi All, Please help me how to remove the records from the file if it is having more number of fields than the required one, before loading into stage Here is the sample records. File is space delimited one chandu 1121324 CC ( 2 spaces) chandu balu 434657 DD (3 spaces) -- failing due to... (10 Replies)
Discussion started by: bbc17484
10 Replies

3. Shell Programming and Scripting

To eliminate the created filename

Hi All, I have two files in the directory file1.txt file2.txt I gave ls -m > output.txt command and I got the output as file1.txt, file2.txt, output.txt But my output should be like file1.txt, file2.txt Thanks in advance. (6 Replies)
Discussion started by: dubuku_01
6 Replies

4. Shell Programming and Scripting

awk statement to eliminate the duplicates

consider the below output cat tablextract2.sql CREATE PROCEDURE after72DeleteTgr(id int) BEGIN END $$ Delimiter ; CREATE PROCEDURE after72DeleteTgr(id int) BEGIN END $$ Delimiter ; # # proc_name1="after72DeleteTgr" # # echo "`awk '{if($3~v){a=1}}a;/elimiter\|DELIMITER/{exit}'... (17 Replies)
Discussion started by: vivek d r
17 Replies

5. Shell Programming and Scripting

How to eliminate ^L

Hi, I am trying to create a text file from data retrieved from a query.The data retrieved is having this character '^L' at regular intervals of the data. How can i eliminate this, Please find below the sample data. I tried sed -e "s/\^L//g" to convert it, but with no luck ^LCODE*SERIAL... (11 Replies)
Discussion started by: ramkiran77
11 Replies

6. Shell Programming and Scripting

Compare and eliminate

Could any one help me to compare the date value say at 10th column with sysdate (i.e current date) and if diffrence is more than 50 days then filter them out from the file. The file contain 10000 records. head file 00971502657744 A671FAHP2EW8BG1369172011HRWS contact information ... (6 Replies)
Discussion started by: zooby
6 Replies

7. Solaris

Solaris:Tomcat-Failed to access resource /WEB-INF/lib/One.jar

Hi All, I have configured the tomcat 6.0.26 and it is working fine in Solaris. Testing JSP and SERVLET program I ensured tomcat is configured properly (My guess). ------------------- Now I placed my Servlet and JSP code under /users/kalai/sample. I have created a soft link to... (1 Reply)
Discussion started by: kalpeer
1 Replies

8. HP-UX

why uptime display "load average: inf, inf, inf"

Hi, Does anyone seem this kind of output from uptime and top where "load average: inf, inf, inf" is this possible problem with the processor? Cpu states: CPU LOAD USER NICE SYS IDLE BLOCK SWAIT INTR SSYS 0 0.10 5.4% 0.0% 4.0% 90.6% 0.0% 0.0% 0.0% 0.0%... (1 Reply)
Discussion started by: robertngo
1 Replies

9. UNIX for Dummies Questions & Answers

boot messages - how to eliminate them

Anyone would know how to get rid off a message that comes up during a boot-up on Solaris? It says that the clusters for this software are not installed. I deleted the software because it was crashing some other stuff but it did not get rid off all the stuff. Yes, I am coming from windows and... (2 Replies)
Discussion started by: softarch
2 Replies
Login or Register to Ask a Question