![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Find number of columns in a file | rahul26 | UNIX for Dummies Questions & Answers | 12 | 05-20-2008 08:20 PM |
| Perl ? - How to find and print the lowest and highest numbers punched in by the user? | some124one | Shell Programming and Scripting | 3 | 03-29-2008 09:04 AM |
| sort with highest wc | ymf | UNIX for Dummies Questions & Answers | 1 | 03-26-2008 11:58 PM |
| How to find number of lines in a file | somesh_p | Shell Programming and Scripting | 2 | 12-19-2007 06:15 PM |
| How to grep a number in a file to find them in another file | ahjiefreak | Shell Programming and Scripting | 7 | 12-12-2007 03:01 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
find the highest number in the file
Hi,
I have a file a.txt and it has values in it Eg :- Quote:
Can any one assit me on this. Thanks |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
sort the file in ascending order and do tail -1 filename
or descending order and do head -1 filename Gaurav |
|
#3
|
|||
|
|||
|
Quote:
max=0 exec 4<&0 exec < file_of_nos while read line do if [ $line -gt $m ] then max=$line else continue fi done echo "Max no is:$max" |
|
#4
|
|||
|
|||
|
manthasirisha, Thank u so much,
Your solution works great, but it does not go beyond 5 lines,..what if i have 10 lines...how can i modify the script to suite that. Thank you so much once again. |
|
#5
|
|||
|
|||
|
maxnum=$(sort -n a.txt |tail -1)
|
|
#6
|
|||
|
|||
|
systemali,
i tried the script with an input file of more that 50 lines and it worked... check ur shell compatibility.. anyway, the easiest method is suggested above .. it should do the trick! good luck, Sirisha |
|
#7
|
|||
|
|||
|
Hi Sirisha,
Yes that worked just fine Quote:
Thanks for all your assistance. |
|||
| Google The UNIX and Linux Forums |