I have numerous dat files (1.dat, 2.dat...) containing 500 numeric values each. I would like to count them, based on their range and obtain a histogram or a counter.
INPUT:
1.dat
1.3
2.16
0.34
......
2.dat
1.54
0.94
3.13
.....
3.dat
2.34
4.12
2.7
.....
OUTPUT:
example-
1.dat: low (2>) - 200 ; medium (3> and 2<) - 50 ; high (3<) -250
(the output can be in any comprehensive format)
I used the following script, in vain!
Code:
#!/bin/csh
set k = 1
while ($k = 250)
set i=0
set low = 0
set medium = 0
set high = 0
foreach line ("`cat $k.dat`")
set j = `printf $line`
if ($j < 2) then @low = $low +1
else if ($j > 2 and <3) then @medium = $medium +1
else if ($j > 3) then @high = $high +1
else
endif
end
echo "$k - $low $medium $high" @k = $k +1
end
I get an error sayin "if: Badly formed number.
Could you please help?
Place this script in the directory containing .dat files, then run it there.
#!/usr/bin/perl
chomp(@files=`ls *.dat`);
for $i (@files){
open I, "$i";
$l=$m=$h=0;
while ($n=<I>){
chomp $n;
$l++ if $n<=2;
$m++ if $n>2 && $n<=3;
$h++ if $n>3;
}
print "$i: low (2>) - $l ; medium (3> and 2<) - $m ; high (3<) - $h\n";
}