Entering edit mode
9.3 years ago
Kumar
▴
170
Hi
I have a multiple column text file, I need to count rows those have only numbers (1....100) in columns [2], [3], [4], [5], else ignore if columns [2], [3], [4], [5] have 0 numbers like yellow. I am trying a following Perl script ..
file example
AG123.4 1234 1 3 4 1
AG123.5 3456 0 0 0 0
AG654.8 9876 4 1 0 0
AG654.7 9999 0 0 1 0
perl script
open(FILE, "<all.txt") or die "Could not open file: $!";
my @lines = 0;
my @column=0;
my $count1=0;
my $count2=0;
while (<FILE>) {
chomp;
$lines++;
$column= split (/\t/);
$column++;
if (@column==0) {
$count1++;
}
elsif (@column>0)
{
$count2++;
}
}
print("lines=$lines column=$column\n");
print "total number of zero in column 1:=", $count1[1],"\n";
print "total number of greater number of zero in column 1:=", $count2[1],"\n";
print "total number of zero in column 2:=", $count1[2],"\n";
print "total number of greater number of zero in column 2:=",$count2[2],"\n";
print "total number of zero in column 3:=", $count1[3],"\n";
print "total number of greater number of zero in column 3:=", $count2[3],"\n";
Thanks for reply. Moreover, I would like extend my query like I need to count total numbers in different columns such as total frequency of 1 in column [2], [3], [4] and [5], total frequency of 2 in column [2], [3], [4] and [5], total frequency of ........in [2], [3], [4], [5]. if all these columns does have 0 ignore these rows....
Since it looks like you're trying to learn Perl, I'll give you the logic and see if you can write the code.
This command showing:
That's because the name of your file is not 'FILE'.