The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 01-04-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,085
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
Then use below scripts seems can help you a little.

Code:
use FileArray;
tie @arr,"FileArray","a.txt";
@brr=sort @{$arr[4]};
print "Min: $brr[0] -- Max: $brr[$#brr]\n";