LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 04-05-2012, 11:59 PM   #1
sparker1970
LQ Newbie
 
Registered: Apr 2012
Location: Warren, MI
Posts: 4

Rep: Reputation: Disabled
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

Last edited by sparker1970; 04-06-2012 at 12:11 AM.
 
Old 04-06-2012, 12:14 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
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]
 
Old 04-06-2012, 11:23 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,608

Rep: Reputation: 673Reputation: 673Reputation: 673Reputation: 673Reputation: 673Reputation: 673
"nan" almost certainly means "not a number". Check for the presence of a blank line at the end of either input file.
 
Old 04-06-2012, 11:45 AM   #4
sparker1970
LQ Newbie
 
Registered: Apr 2012
Location: Warren, MI
Posts: 4

Original Poster
Rep: Reputation: Disabled
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] [awk] division by NaN dhodho Programming 10 10-15-2012 07:38 PM
[SOLVED] Problem with if statement in awk in AIX sukhdip AIX 3 01-31-2012 03:28 AM
Print NaN using awk dhodho Programming 6 06-24-2010 08:05 AM
[SOLVED] variable substitution in awk statement emmalg Linux - Software 12 07-02-2009 09:39 AM
how to keep Field Separator in AWK when using a sub statement tmcguinness Programming 4 02-09-2009 03:24 PM


All times are GMT -5. The time now is 06:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration