Hi
I'm reallly new to perl - I have a file which contains siome text and a series of 0's and 1's - I need to count the number of 1's in the file. Can anyone give me some help please?
OOP
Hi
I'm reallly new to perl - I have a file which contains siome text and a series of 0's and 1's - I need to count the number of 1's in the file. Can anyone give me some help please?
OOP
No homework. Its against the rules.
deleted........
Hi
I submitted a request earlier asking how to read a file with text and number and counts the number of bin 1's (ie. number 1's) in the file.
Messaage to anbu23, this is not homework, I usually work with Object Oriented Programming (Java) and I have never used perl before. I have a program from another person who has since left the company and I want to add a few extra functions to it.
If anyone can help me, I'd appreciate it, I need to somehow read the file, disregard the text and count the number of 1's in the file.
Cheers
Hi
I submitted a request earlier asking how to read a file with text and number and counts the number of bin 1's (ie. number 1's) in the file.
Messaage to anbu23, this is not homework, I usually work with Object Oriented Programming (Java) and I have never used perl before. I have a program from another person who has since left the company and I want to add a few extra functions to it.
If anyone can help me, I'd appreciate it, I need to somehow read the file, disregard the text and count the number of 1's in the file.
Cheers
you want it in perl or shell ???
But on duplicate posts !!!!!!!!!!!
Hi Kamitsin
Perl please, because there is no spaces or commas between the numbers, I can't seem to construct an array in which I can input them and then count the occurrences of bin 1's
Thanks
This will give you the count of '1' plus 1 because of end-of-line:
sed 's/[^1]//g;/^$/d' input_file | paste -d'\0' -s - | wc -c
Oop,
I just replied to this very same request by you.
You are breaking the rules of no duplicate postings.
Threads merged --reborg
thanks for your help
fold -w 1 file | grep -c "1"
#!/usr/bin/perl
$cnt=0;
while( <> )
{
while ( /(.)/g) {
$cnt++ if( $1 eq "1" )
}
}
print $cnt."\n" ;