Go Job Hunting at the LQ Job Marketplace
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-05-2012, 10:59 PM   #1
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:


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.


Last edited by sparker1970; 04-05-2012 at 11:11 PM.
Old 04-05-2012, 11:14 PM   #2
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian except for netbook still on Slackware 13.37 (and I have to support Ubuntu)
Posts: 8,572
Blog Entries: 30

Rep: Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182Reputation: 1182
With the input files as described and the command shown (less the second |) I cannot reproduce the problem:
c@CW8:/tmp$ paste file1.txt file2.txt | awk '{print $2/$1};'
c@CW8:/tmp$ awk --version
GNU Awk 3.1.8
Old 04-06-2012, 10:23 AM   #3
Senior Member
Registered: Aug 2009
Distribution: CentOS
Posts: 2,103

Rep: Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884Reputation: 884
"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
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!


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] 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

All times are GMT -5. The time now is 02:01 AM.

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