Unix/Linux Go Back    


UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

Help with Median

UNIX for Dummies Questions & Answers


 
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 07-16-2009   -   Original Discussion by zajtat
zajtat's Unix or Linux Image
zajtat zajtat is offline
Registered User
 
Join Date: Jul 2009
Last Activity: 22 August 2016, 6:09 PM EDT
Posts: 101
Thanks: 15
Thanked 0 Times in 0 Posts
Help with Median

Hi,

I know this question has been asked before, but I'd like to ask for some explanation rather than solution regarding finding median in unix.
I've got a simple one column file with over 2 million numbers and I need to find its median. The file looks like this:
0.123
0.235
0.890
0.000 etc (just plain numbers).

The solution that I've found in forum answers was:
1) find the number of lines with this code:

wc -l filename

In my case it is: 2543887

2) if the number is not even (like in my case) than the median can be found with this code:

cat filename| head -$2543887 | tail -1

My question is how head -2543887 is different to head -$2543887? What does the dollar sign do?

Many thanks in advance!
Sponsored Links
    #2  
Old Unix and Linux 07-16-2009   -   Original Discussion by zajtat
rakeshawasthi's Unix or Linux Image
rakeshawasthi rakeshawasthi is offline
Registered User
 
Join Date: Aug 2004
Last Activity: 27 May 2014, 10:05 PM EDT
Location: India
Posts: 379
Thanks: 0
Thanked 0 Times in 0 Posts

Code:
cat filename| head -$2543887 | tail -1

Is it a correct command? Did you try this?? and cant see any maths here to get the median. am confused.
Sponsored Links
    #3  
Old Unix and Linux 07-16-2009   -   Original Discussion by zajtat
zajtat's Unix or Linux Image
zajtat zajtat is offline
Registered User
 
Join Date: Jul 2009
Last Activity: 22 August 2016, 6:09 PM EDT
Posts: 101
Thanks: 15
Thanked 0 Times in 0 Posts
Yes, I've tried it and the answer was 0.0751, while typing just
cat filename | head -$254887 | tail -1 gives 9.9997. So, these two command lines do something different?

I'm new to Unix. Do you think what I found won't give me the median? What do you think I should use?

Many thanks!

---------- Post updated at 07:59 AM ---------- Previous update was at 07:56 AM ----------

sorry, I meant that typing
cat filename | head -2543887 |tail -1 gives 9.9997
So, typing it with or without the dollar sign gives different outputs...
    #4  
Old Unix and Linux 07-16-2009   -   Original Discussion by zajtat
rakeshawasthi's Unix or Linux Image
rakeshawasthi rakeshawasthi is offline
Registered User
 
Join Date: Aug 2004
Last Activity: 27 May 2014, 10:05 PM EDT
Location: India
Posts: 379
Thanks: 0
Thanked 0 Times in 0 Posts
i did not knew this $ thing with head...
and for median, i think you need to do the statistcs part. I dont know the formula Linux
Sponsored Links
    #5  
Old Unix and Linux 07-16-2009   -   Original Discussion by zajtat
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 12 December 2017, 10:42 AM EST
Location: Foxborough, MA
Posts: 8,203
Thanks: 231
Thanked 785 Times in 732 Posts
I don't follow, how the head|tail can calculate the median.
Sponsored Links
    #6  
Old Unix and Linux 07-16-2009   -   Original Discussion by zajtat
zajtat's Unix or Linux Image
zajtat zajtat is offline
Registered User
 
Join Date: Jul 2009
Last Activity: 22 August 2016, 6:09 PM EDT
Posts: 101
Thanks: 15
Thanked 0 Times in 0 Posts
Unofrtunately, I'm new to Unix and don't know how the head and tail can calculate the median, but I thought that the dollar sign is a trick. This is why I asked the question in the first place.
Does anyone know how to calculate the mean, then?

---------- Post updated at 08:14 AM ---------- Previous update was at 08:10 AM ----------

sorry, I meant how to calculate the median
Sponsored Links
    #7  
Old Unix and Linux 07-16-2009   -   Original Discussion by zajtat
vgersh99's Unix or Linux Image
vgersh99 vgersh99 is online now Forum Advisor  
Forum Advisor
 
Join Date: Feb 2005
Last Activity: 12 December 2017, 10:42 AM EST
Location: Foxborough, MA
Posts: 8,203
Thanks: 231
Thanked 785 Times in 732 Posts
Google is your friend
Sponsored Links
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk to median riderman Shell Programming and Scripting 5 01-27-2009 08:06 PM



All times are GMT -4. The time now is 11:54 AM.