find biggest number inside file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find biggest number inside file
# 1  
Old 11-11-2012
find biggest number inside file

Hi,

I wanna find the biggest number inside of a file

this is kind of example of file:
Code:
9
11
55

then i just wanna print out the biggest number

i had try sed filenale | sort -k1,1n | paste -s -d',' -
but i had no success ...

Last edited by radoulov; 11-11-2012 at 03:10 PM..
# 2  
Old 11-11-2012
Code:
sort -n filename | tail -1

This User Gave Thanks to Yoda For This Post:
# 3  
Old 11-11-2012
Code:
awk 'BEGIN {big=$1} {if($1>big) big=$1} END {print big}' input_file

you can use this code to find the biggest number. and here $1 means first field i,e here we are having only one column.

Last edited by radoulov; 11-11-2012 at 03:10 PM.. Reason: Code tags.
# 4  
Old 11-11-2012
also try:
Code:
awk '{$1>b?b=$1:0} END{print b}' infile

# 5  
Old 11-12-2012
Quote:
Originally Posted by rdrtx1
also try:
Code:
awk '{$1>b?b=$1:0} END{print b}' infile

Works well on positive numbers, but would be in trouble if all numbers were negative.
# 6  
Old 11-12-2012
Try like..
Code:
 sort -rn test.txt|head -1

---------- Post updated at 04:29 AM ---------- Previous update was at 04:28 AM ----------

Please post your test data ,i will try...
# 7  
Old 11-12-2012
Code:
perl -e 'biggest = chop(<>);while(<>) { if(chop() > biggest) biggest = chop();} print biggest;'

Hope I'm right.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find biggest values on replicates

Dear All I was wondering if someone of you know how to resolve an issue that I met. In particular I have a file like this: ENSMUSG01 chr1 77837902 77853530 ENSMUSG02 chr2 18780447 18811972 ENSMUSG02 chr2 18780453 18811626 ENSMUSG02 chr2 18807356 18811987 ENSMUSG03 chr3 142575634 142576538... (6 Replies)
Discussion started by: giuliangiuseppe
6 Replies

2. Shell Programming and Scripting

How to find biggest word in a file....?

With any cmd like sed grep ask etc... (1 Reply)
Discussion started by: sidpatil
1 Replies

3. Shell Programming and Scripting

To check for a number inside the file in UNIX

Hi Gurus I am a newbie to Unix programming and I am having a difficulty in finding out a number which is present in a file and storing it in a variable so that i can use it in my shell script. The content of the file "count" is: Count of the files=11 I need to just store the value 11 in... (8 Replies)
Discussion started by: vikramgk9
8 Replies

4. Shell Programming and Scripting

How to find the Missing date inside the FILE?

Hi am using Unix AIX Ksh have a FILE CAT FILE 08/02/2013 16/02/2013 18/02/2013 I need the Outputs as Missing date are 09/02/2013 to 15/02/2013,17/02/2013 can anyone help me !!! (1 Reply)
Discussion started by: Venkatesh1
1 Replies

5. Shell Programming and Scripting

KSH SHELL: problem calculation number of lines inside compressed file

Hi Gurus, I am working with a korn shell script to simplify some operations of calculation number of lines inside compressed file. The called function (inside a cycle) is the following: ######################################### # F.ne: CheckCount #########################################... (3 Replies)
Discussion started by: GERMANICO
3 Replies

6. Shell Programming and Scripting

how to find the pattern inside the file and replace it

hello everybody, I have a group of file eg- sample1 sample2 sample3 sample4 each file contain this :- cat sample1 SEQ_NUM,1,UPESI1 My requirement is to change the value-UPESI1 to UPE10 in file which contain this pattern -UPESI1. any help is appreciated. (2 Replies)
Discussion started by: abhigrkist
2 Replies

7. UNIX for Dummies Questions & Answers

How to find a file with specific string inside it.

Hi , Is there any way i can find a file with specific word inside it. For example if i want to find a file which has some text written inside it. How would i form a command to search them? (3 Replies)
Discussion started by: pinga123
3 Replies

8. UNIX for Dummies Questions & Answers

Find something inside a file

Hi, this is the problem i'm facing i need a check some file having some word like gzip or tar ,the way i normally do is grep gzip filenamethe thing is that i had some 1000 files to be checked is that the only way or can i customize it by some script ,i know there is some way ,but i need some... (4 Replies)
Discussion started by: malickhat
4 Replies

9. UNIX for Dummies Questions & Answers

Disk Usage in GB and Unix command to find the biggest file/folder

Hi All, Please help me out 1) Command to find the disk usage in GB. I know that du -k will give in kilobites. 2) How to find the Biggest file/folder in a given set of files/folders. Thanks in advance Regards, Manas (8 Replies)
Discussion started by: manas6
8 Replies

10. Shell Programming and Scripting

finding biggest number

I think my script is working but i am trying to understand while I am tracing to see if it's realli working.. can somebody please comment.. also. is there different way to write this in shell? sh -x findbiggestnum 1 2 3 + big=0 + big=1 + big=2 + big=3 + echo 3 3 big=0 ... (3 Replies)
Discussion started by: hankooknara
3 Replies
Login or Register to Ask a Question