From: pavan734 on
Hi,
Suppose I have got 3 files like this

file1.txt file2.txt file3.txt
abc gsywg wrtw
def abc abc hshs dhwu wwg
dadq aft hhs gtc ffs
abc ttsg abc hhshh abc

Assume that all the files are of same no. of lines

I need a script that compares each line of all the files for the
pattern "abc" and print the number of lines not containing the pattern
"abc" in all the files

In the above example, the script must print 1 because only 3rd line of
all the files is not containing the pattern "abc". I think you
understood my question, if not pls ask me again, I will eloborate more.

From: Tad McClellan on
pavan734(a)gmail.com <pavan734(a)gmail.com> wrote:
> Hi,
> Suppose I have got 3 files like this
>
> file1.txt file2.txt file3.txt
> abc gsywg wrtw
> def abc abc hshs dhwu wwg
> dadq aft hhs gtc ffs
> abc ttsg abc hhshh abc
>
> Assume that all the files are of same no. of lines
>
> I need a script that compares each line of all the files for the
> pattern "abc" and print the number of lines not containing the pattern
> "abc" in all the files
>
> In the above example, the script must print 1 because only 3rd line of
> all the files is not containing the pattern "abc". I think you
> understood my question, if not pls ask me again, I will eloborate more.


----------------------
#!/usr/bin/perl
use warnings;
use strict;

my @file1 = ('abc', 'def abc', 'dadq aft', 'abc ttsg');
my @file2 = ('gsywg', 'abc hshs', 'hhs gtc', 'abc hhshh');
my @file3 = ('wrtw', 'dhwu wwg', 'ffs', 'abc');

my $cnt=0;
foreach my $i ( 0 .. $#file1 ) {
next if $file1[$i] =~ /abc/;
next if $file2[$i] =~ /abc/;
next if $file3[$i] =~ /abc/;
$cnt++;
}

print "$cnt\n";
----------------------


--
Tad McClellan SGML consulting
tadmc(a)augustmail.com Perl programming
Fort Worth, Texas
From: pavan734 on
On Feb 15, 4:53 pm, Tad McClellan <t...(a)augustmail.com> wrote:
> pavan...(a)gmail.com <pavan...(a)gmail.com> wrote:
> > Hi,
> > Suppose I have got 3 files like this
>
> > file1.txt file2.txt file3.txt
> > abc gsywg wrtw
> > def abc abc hshs dhwu wwg
> > dadq aft hhs gtc ffs
> > abc ttsg abc hhshh abc
>
> > Assume that all the files are of same no. of lines
>
> > I need a script that compares each line of all the files for the
> > pattern "abc" and print the number of lines not containing the pattern
> > "abc" in all the files
>
> > In the above example, the script must print 1 because only 3rd line of
> > all the files is not containing the pattern "abc". I think you
> > understood my question, if not pls ask me again, I will eloborate more.
>
> ----------------------
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> my @file1 = ('abc', 'def abc', 'dadq aft', 'abc ttsg');
> my @file2 = ('gsywg', 'abc hshs', 'hhs gtc', 'abc hhshh');
> my @file3 = ('wrtw', 'dhwu wwg', 'ffs', 'abc');
>
> my $cnt=0;
> foreach my $i ( 0 .. $#file1 ) {
> next if $file1[$i] =~ /abc/;
> next if $file2[$i] =~ /abc/;
> next if $file3[$i] =~ /abc/;
> $cnt++;
>
> }
>
> print "$cnt\n";
> ----------------------
>
> --
> Tad McClellan SGML consulting
> t...(a)augustmail.com Perl programming
> Fort Worth, Texas- Hide quoted text -
>
> - Show quoted text -

I think you have misunderstood. file1 name is file1.txt and `abc',
'def abc', 'dadq aft', `abc ttsg' are its contents. Similarly for
file2.txt and file3.txt. Note that the contents can be anything and my
real application files are containing as many as 2000 lines.


From: Mirco Wahab on
pavan734(a)gmail.com wrote:
> Hi,
> Suppose I have got 3 files like this
>
> file1.txt file2.txt file3.txt
> abc gsywg wrtw
> def abc abc hshs dhwu wwg
> dadq aft hhs gtc ffs
> abc ttsg abc hhshh abc
>
> Assume that all the files are of same no. of lines
>
> I need a script that compares each line of all the files for the
> pattern "abc" and print the number of lines not containing the pattern
> "abc" in all the files
>
> In the above example, the script must print 1 because only 3rd line of
> all the files is not containing the pattern "abc". I think you
> understood my question, if not pls ask me again, I will eloborate more.

use strict;
use warnings;

my $term = qr/abc/;

open my $f1, '<', 'file1.txt';
open my $f2, '<', 'file2.txt';
open my $f3, '<', 'file3.txt';

my ($count, $line);
while( ! eof($f1) and ! eof($f2) and ! eof($f3) ) {
my @lines = (scalar <$f1>, scalar <$f2>, scalar <$f3>);
++$line;
print ++$count, ". # $line\n" unless grep /$term/, @lines;
}

print "Total: $count\n";



Regards

M.
From: Gunnar Hjalmarsson on
pavan734(a)gmail.com wrote:
> On Feb 15, 4:53 pm, Tad McClellan <t...(a)augustmail.com> wrote:
>>pavan...(a)gmail.com <pavan...(a)gmail.com> wrote:

<homework assignment snipped>

<solution snipped>

> I think you have misunderstood. file1 name is file1.txt and `abc',
> 'def abc', 'dadq aft', `abc ttsg' are its contents. Similarly for
> file2.txt and file3.txt.

Then adapt the solution accordingly!

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl