LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 10: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-05-2012 at 11:11 PM.
 
Old 04-05-2012, 11:14 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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, 10:23 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
"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, 10: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



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] Problem with if statement in awk in AIX sukhdip AIX 7 07-29-2015 01:18 AM
[SOLVED] [awk] division by NaN dhodho Programming 10 10-15-2012 06:38 PM
Print NaN using awk dhodho Programming 6 06-24-2010 07:05 AM
[SOLVED] variable substitution in awk statement emmalg Linux - Software 12 07-02-2009 08:39 AM
how to keep Field Separator in AWK when using a sub statement tmcguinness Programming 4 02-09-2009 02:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:25 AM.

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
Open Source Consulting | Domain Registration