![]() |
|
There's more than one way to do things | |
PerlMonks |
Find highest and lowest numerical values for columns in a fileby vdb (Initiate) |
on Jun 24, 2011 at 02:12 UTC ( [id://911189]=perlquestion: print w/replies, xml ) | Need Help?? |
vdb has asked for the wisdom of the Perl Monks concerning the following question:
Bonjour Monks.
I am working with some files containing a header then some columns of actual data, usually 7 or so data columns in total. Im interested in finding out 2 things about this data: - the highest and lowest data values in columns 2 and 3 - the sequential step i.e the amount the value changes by between these data values (which is always constant). Heres an excert of the data:
In this example I would want the results to show the following: For File ABC.dat The Max Value Column 2 = 4001 The Min Value Column 2 = 3961 The Min Value Column 3 = 4081 The Max Value Column 3 = 4161 The Step in Column 2 = 20 The Step in Column 3 = 40 Can this be done?! As of now I am using a very convuluted and I think inefficient method. I am creating a new file with the header removed, then sorting the data on a īper columnī basis and exporting this to another new file, then printing the first and last line in this newest file to show the lowest and highest number for that column. e.g.
followed by awk 'NR==1;END{print}' Column2.datNot ideal but it does the trick eventually....though Im sure you will agree that there has to be a better way to do this, but at the moment Im just too dumb to know how! Cheers. VDB V
Back to
Seekers of Perl Wisdom
|
|