LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Getting -nan in output of awk statement (https://www.linuxquestions.org/questions/linux-newbie-8/getting-nan-in-output-of-awk-statement-938401/)

sparker1970 04-05-2012 10:59 PM

Getting -nan in output of awk statement
 
I have 2 files that are created by other processes where I need to divide the value of one file by the value of the other.

I am currently using the following command:
paste file1.txt file2.txt | | awk '{print $2/$1};' > file3.txt

I am getting the correct output but I am also getting a second line that contains -nan. So if file1.txt = 10 and file2.txt = 50 I am getting the following output:

5
-nan

I am very much a newbie to Linux and I am trying to use it for some file manipulation I simply cannot do in Windows. I apologize if my question seems basic. I am guessing the -nan has something to do with the fact I am dividing but I have no idea and haven't found anything yet in my searches.

Thanks

catkin 04-05-2012 11:14 PM

With the input files as described and the command shown (less the second |) I cannot reproduce the problem:
Code:

c@CW8:/tmp$ paste file1.txt file2.txt | awk '{print $2/$1};'
5
c@CW8:/tmp$ awk --version
GNU Awk 3.1.8
[snip]


rknichols 04-06-2012 10:23 AM

"nan" almost certainly means "not a number". Check for the presence of a blank line at the end of either input file.

sparker1970 04-06-2012 10:45 AM

Getting -nan in output of awk statement
 
rk worked perfectly. There was a linefeed inserted immediately following the integer within the file. Using vi I edited the 2 originals to be sure and it worked. I then found where it got inserted in the workflow previous to my current script.

Issue solved!


All times are GMT -5. The time now is 10:41 PM.