![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to calculate the maximum value & min value | gobinath | Shell Programming and Scripting | 1 | 05-29-2008 12:01 AM |
| TO find the word which occurs maximum number of times | aajan | Shell Programming and Scripting | 5 | 01-11-2008 04:11 AM |
| Find out the maximum growing file in a mount | raman1605 | UNIX for Dummies Questions & Answers | 3 | 10-01-2007 08:25 PM |
| How to find the maximum # of PIDs | stevefox | UNIX for Dummies Questions & Answers | 8 | 08-04-2006 04:22 AM |
| Environment variable maximum value | tonyv | Shell Programming and Scripting | 2 | 03-15-2005 05:25 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Need to find the mimimum & maximum
Hi,
I've got a file with a list of values. I need to find the minimum & maximum number a particular column in that file. For example, the file can look like, 1 2 3 45 32 2 3 5 36 87 5 8 3 96 23 8 9 6 24 56 So, in the above list, I need to find out the minimum & maximum from the numbers in the 4th Column & 5th Column. Note: The original file contains more than 1000 lines. Regards Ashok Y |
|
||||
|
Hi, you may use perl, tie your file to below Module, then you can treat your file as a two-dimension array by column.
Code:
package FileArray;
sub _makeArr{
$file=shift;
open FH,"<$file";
while(<FH>){
my @tmp=split(" ",$_);
for($i=0;$i<=$#tmp;$i++){
$arr[$i][$.-1]=$tmp[$i];
}
}
close FH;
}
sub TIEARRAY{
my($self,$file)=(@_);
_makeArr($file);
return bless \@arr,$self;
}
sub FETCH{
my($self,$ind)=(@_);
return $arr[$ind];
}
sub STORE{
my($self,$ind)=(@_);
return $arr[$ind];
}
1
Code:
use FileArray;
tie @arr,"FileArray","a.txt";
@brr=sort @{$arr[4]};
print "Min: $brr[0] -- Max: $brr[$#brr]\n";
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| perl, perl shift, shift, shift perl |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|