Get large number question 
Author Message
 Get large number question

Hello  Everybody
       How to write a awk command to get a large number?

EXAMPLE:
       I have a file like:  abc 146
                                 def  40
                                 dee ab 98
                                 hhh qqq 146

      OUTPUT:  abc 146
                        hhh qqq 146
                                                         Thank



Tue, 16 Jul 2002 03:00:00 GMT  
 Get large number question


Quote:
>Hello  Everybody
>       How to write a awk command to get a large number?

>EXAMPLE:
>       I have a file like:  abc 146
>                                 def  40
>                                 dee ab 98
>                                 hhh qqq 146

>      OUTPUT:  abc 146
>                        hhh qqq 146
>                                                         Thank

It's unclear what you want.

these would produce that output:

awk '$NF>145 {print}' infile

awk '$NF==146 {print}' infile

awk '/146/ {print}' infile

in the above the {print} is redundant, i.e.

awk '/146/' infile

works too.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Wed, 17 Jul 2002 03:00:00 GMT  
 Get large number question


%        How to write a awk command to get a large number?

This needs some work but:

 awk '/MAXDOUBLE/ { print $NF }' /usr/include/values.h

% EXAMPLE:
%        I have a file like:  abc 146
%                                  def  40
%                                  dee ab 98
%                                  hhh qqq 146

It seems like what you want is the largest number from a data set. If the
number is always in the last field, you can do this:
 BEGIN {
    nobigs = 0       # count of lines with the largest number
    big = -10241024  # initialise the largest number to something very small
 }
 # if the number is bigger than anything we've seen so far, get rid of
 # anything we've saved
 $NF > big { big = $NF; nobigs = 0 }

 # if the number is the same as the biggest we've seen so far, save it
 $NF == big { bigs[nobigs++] = $0 }
 END { for (i = 0; i < nobigs; i++) print bigs[i] }
--

Patrick TJ McPhee
East York  Canada



Wed, 17 Jul 2002 03:00:00 GMT  
 Get large number question

   >Hello  Everybody
   >How to write a awk command to get a large number?
   >EXAMPLE:
   >I have a file like:  abc 146
   >def  40
   >dee ab 98
   >hhh qqq 146
   >OUTPUT:  abc 146
   >hhh qqq 146
   >Thank
If you are looking for which records have the largest number at the end,
maybe something like:
awk '$NF+0==biggest{biglist=sprintf("%s\n%s",biglist,$0)}
     $NF+0>biggest{biglist=$0;biggest=$NF}
     END{print biglist}'


Wed, 17 Jul 2002 03:00:00 GMT  
 Get large number question

Quote:



> %        How to write a awk command to get a large number?

> This needs some work but:

>  awk '/MAXDOUBLE/ { print $NF }' /usr/include/values.h

> % EXAMPLE:
> %        I have a file like:  abc 146
> %                                  def  40
> %                                  dee ab 98
> %                                  hhh qqq 146

> It seems like what you want is the largest number from a data set. If the
> number is always in the last field, you can do this:
>  BEGIN {
>     nobigs = 0       # count of lines with the largest number
>     big = -10241024  # initialise the largest number to something very small
>  }

In general it's bettter [ i.e. safer ] not to do it like this but to
initialise on the first pass. Then the initial value of big will never
be too large. So something like this :

!big { big=$NF}

or

NF==1 { big=$NF }

Quote:
>  # if the number is bigger than anything we've seen so far, get rid of
>  # anything we've saved
>  $NF > big { big = $NF; nobigs = 0 }

>  # if the number is the same as the biggest we've seen so far, save it
>  $NF == big { bigs[nobigs++] = $0 }
>  END { for (i = 0; i < nobigs; i++) print bigs[i] }
> --

> Patrick TJ McPhee
> East York  Canada


__________________________________________________________________

           o                     Eiso AB

                 o               Dept. of Biochemistry
                                 University of Groningen                
                                 The Netherlands                      
                  o  
            . .    
         o   ^                  
         |   -   _              
          \__|__/              
             |                  
             |
            / \
           /   \
           |   |
________ ._|   |_. ________________________________________________



Fri, 19 Jul 2002 03:00:00 GMT  
 Get large number question

% In general it's bettter [ i.e. safer ] not to do it like this but to
% initialise on the first pass. Then the initial value of big will never
% be too large. So something like this :
%
% !big { big=$NF}

This is obviously wrong if the largest value is 0 and there are negative
numbers.

% NF==1 { big=$NF }

I'll buy this one.
--

Patrick TJ McPhee
East York  Canada



Sat, 20 Jul 2002 03:00:00 GMT  
 Get large number question
Quote:


> % In general it's bettter [ i.e. safer ] not to do it like this but to
> % initialise on the first pass. Then the initial value of big will never
> % be too large. So something like this :
> %
> % !big { big=$NF}

> This is obviously wrong if the largest value is 0 and there are negative
> numbers.

Oops, you're right. big=="" { big=$NF} would do the job though [I hope].

More general would be perhaps to use { big=$NF+0 } as action statement
which works even if $NF equals "" for some reason.

Quote:
> % NF==1 { big=$NF }

> I'll buy this one.
it's free
> --

> Patrick TJ McPhee
> East York  Canada


--
__________________________________________________________________

           o                     Eiso AB

                 o               Dept. of Biochemistry
                                 University of Groningen                
                                 The Netherlands                      
                  o  
            . .    


          \__|__/                http://md.chem.rug.nl/~eiso
             |                  
             |
            / \
           /   \
           |   |
________ ._|   |_. ________________________________________________



Sat, 20 Jul 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. largest number/data type conversion question

2. Tcl question dealing with large numbers

3. Getting Cancel Button working during large processes

4. partition a large file into a number of small ones

5. dealing with large numbers(?)

6. Number's Larger than 1,000,000

7. speed of execution on large number of records

8. clarion stability with large numbers of records

9. Counting large number of records in CW 2...

10. Organizing large numbers of vi's

11. Large Numbers

12. largest or smallest number

 

 
Powered by phpBB® Forum Software