Re: counters for lines

2004-01-20 Thread Wiggins d Anconia
> On Tue, 20 Jan 2004 13:39:44 -0500
> "Anthony J Segelhorst" <[EMAIL PROTECTED]> wrote:
> 
> > I have the following output, and each value that is separated by
comma is 
> > a variable:
> > 
> > servera,serverb,109,aix4-r1,server
> > servera,serverb,109,aix4-r1,server
> > servera,serverb,109,aix4-r1,server
> > servera,serverb,109,aix4-r1,server
> > servera,serverb,109,aix4-r1,server
> > servera,serverb,109,hpux10,server
> > servera,serverb,109,solaris2,server
>  
> > 
> > I am trying to set up a counter that would actually output the data
to be:
> > 
> > servera,serverb,109,aix4-r1,server,5
> > servera,serverb,109,hpux10,server,1
> > servera,serverb,109,solaris2,server,10
> > 
> > Does anyone any suggestion on how to set up a counter to count the
lines 
> > until a different line shows up.  I already have the list sorted, so I 
> 
> 
> 
> system ("uniq $file_with_duplicates $file_sans_duplicates");
> 
> Then work on $file_sans_duplicates
> 

Please DON'T do it this way. Shelling out from Perl to a program like
'uniq' should be a last resort. If you are going to suggest such
procedures at least do them justice by using full paths, and doing the
proper amount of error handling, the above is not sufficient and
shouldn't be considered so.  In most cases it is slower, less secure,
and more error prone.  Some will disagree and that is fine, but at the
very least indicate that this is a quick and dirty hack and there are
times that quick and dirty is NOT elegant. Chances are if the OP had to
ask such a question they can't wield 'system' properly.

http://danconia.org 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: counters for lines

2004-01-20 Thread James Edward Gray II
On Jan 20, 2004, at 2:52 PM, Anthony J Segelhorst wrote:

James Edward Gray II <[EMAIL PROTECTED]>
01/20/2004 02:11 PM
I got this script written from James gave me:
Right here you left out:

use strict;
use warnings;
While not required, they're and important step in gaining Perl mastery. 
 Start forming good habits now.

$servers = "/tmp/ep_report_db_test1.log";
my $servers = '/tmp/ep_report_db_test1.log';	# will get past strict

open (SERVERFILE, "<$servers");
Just out of curiosity, did you try my script?  It handled opens for 
you, if called as documented and thus didn't need them to be hard 
coded.

If you want to handle you own opens though, you must make sure they 
succeed:

open SERVERFILE, $servers or die "File error:  $!\n";

my($last, $counter) = (undef, 0);
while () {
chomp;
if ($last) {
 if ($_ eq $last) { $counter++; }
 else {
 print 
"$last,$counter\n";
 undef $last;
 $counter = 0;
I messed the above three lines up.  My fault.  Try these instead:

print "$last,$counter\n";
$last = $_;
$counter = 1;
 }
 }
 else {
 $last = $_;
 $counter++;
 }
I also left out an important line right here:

	print "$last,$counter\n" if eof;

}

But now I am having problems counting if there is one record of that 
line?
 Any suggestions?
See if the above fixes you up.  Sorry about the mistakes.

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: counters for lines

2004-01-20 Thread Owen
On Tue, 20 Jan 2004 13:39:44 -0500
"Anthony J Segelhorst" <[EMAIL PROTECTED]> wrote:

> I have the following output, and each value that is separated by comma is 
> a variable:
> 
> servera,serverb,109,aix4-r1,server
> servera,serverb,109,aix4-r1,server
> servera,serverb,109,aix4-r1,server
> servera,serverb,109,aix4-r1,server
> servera,serverb,109,aix4-r1,server
> servera,serverb,109,hpux10,server
> servera,serverb,109,solaris2,server
 
> 
> I am trying to set up a counter that would actually output the data to be:
> 
> servera,serverb,109,aix4-r1,server,5
> servera,serverb,109,hpux10,server,1
> servera,serverb,109,solaris2,server,10
> 
> Does anyone any suggestion on how to set up a counter to count the lines 
> until a different line shows up.  I already have the list sorted, so I 



system ("uniq $file_with_duplicates $file_sans_duplicates");

Then work on $file_sans_duplicates

-- 
Owen


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: counters for lines

2004-01-20 Thread Anthony J Segelhorst
James Edward Gray II <[EMAIL PROTECTED]>
01/20/2004 02:11 PM

 
To: "Anthony J Segelhorst" <[EMAIL PROTECTED]>
cc: [EMAIL PROTECTED]
    Subject:    Re: counters for lines


On Jan 20, 2004, at 12:39 PM, Anthony J Segelhorst wrote:

> I have the following output, and each value that is separated by comma 
> is
> a variable:
>
> servera,serverb,109,aix4-r1,server
> servera,serverb,109,aix4-r1,server
> servera,serverb,109,aix4-r1,server
> servera,serverb,109,aix4-r1,server
> servera,serverb,109,aix4-r1,server
> servera,serverb,109,hpux10,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
>
>
> I am trying to set up a counter that would actually output the data to 
> be:
>
> servera,serverb,109,aix4-r1,server,5
> servera,serverb,109,hpux10,server,1
> servera,serverb,109,solaris2,server,10
>
> Does anyone any suggestion on how to set up a counter to count the 
> lines
> until a different line shows up.  I already have the list sorted, so I
> just need to compare the new string to old string and if they are the 
> same
> increase the counter, and if they are different start a new counter.

>How about something like this (untested code):

>#!/usr/bin/perl

>use strict;
>use warnings;

>my($last, $counter) = (undef, 0);
>while (<>) {# call with:  perl script_name FILE(S) TO COUNT > 

>OUTPUT_FILE
>chomp;
>if ($last) {
>if ($_ eq $last) { $counter++; }
>else {
>print "$last,$counter\n";
>undef $last;
>$counter = 0;
>}
>}
>else {
>$last = $_;
>$counter++;
>}
>}

>__END__

>James


I got this script written from James gave me:

$servers = "/tmp/ep_report_db_test1.log";
open (SERVERFILE, "<$servers");

my($last, $counter) = (undef, 0);
while () {   # call with:  perl script_name FILE(S) TO 
COUNT > OUTPUT_FILE
chomp;
 
if ($last) {
 if ($_ eq $last) { $counter++; }
 else {
 print "$last,$counter\n";
 undef $last;
 $counter = 0;
 }
 }
 else {
 $last = $_;
 $counter++;
 }
}


But now I am having problems counting if there is one record of that line? 
 Any suggestions?

Example:
servera,serverb,109,w32-ix86,client,1

But I am not getting a count of that line?


Anthony J Segelhorst
Enterprise Systems Management Team
Phone: 937-495-1876
Email: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




This email has been scanned for all viruses by the MessageLabs SkyScan
service.___





This email has been scanned for all viruses by the MessageLabs SkyScan
service.___

Note:  Please update your email address for this user to reflect the
new MeadWestvaco Corporation.  MeadWestvaco employee email addresses
are in the format of [EMAIL PROTECTED] 

This electronic message contains information from MeadWestvaco
Corporation or subsidiary companies, which may be confidential,
privileged or otherwise protected from disclosure.  The
information is intended to be used solely by the recipient(s)
named.  If you are not an intended recipient, be aware that
any review, disclosure, copying, distribution or use of this
transmission or its contents is prohibited.  If you have
received this transmission in error, please notify MeadWestvaco
immediately at [EMAIL PROTECTED]
___

Re: counters for lines

2004-01-20 Thread James Edward Gray II
On Jan 20, 2004, at 12:39 PM, Anthony J Segelhorst wrote:

I have the following output, and each value that is separated by comma 
is
a variable:

servera,serverb,109,aix4-r1,server
servera,serverb,109,aix4-r1,server
servera,serverb,109,aix4-r1,server
servera,serverb,109,aix4-r1,server
servera,serverb,109,aix4-r1,server
servera,serverb,109,hpux10,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
I am trying to set up a counter that would actually output the data to 
be:

servera,serverb,109,aix4-r1,server,5
servera,serverb,109,hpux10,server,1
servera,serverb,109,solaris2,server,10
Does anyone any suggestion on how to set up a counter to count the 
lines
until a different line shows up.  I already have the list sorted, so I
just need to compare the new string to old string and if they are the 
same
increase the counter, and if they are different start a new counter.
How about something like this (untested code):

#!/usr/bin/perl

use strict;
use warnings;
my($last, $counter) = (undef, 0);
while (<>) {	# call with:  perl script_name FILE(S) TO COUNT > 
OUTPUT_FILE
	chomp;
	if ($last) {
		if ($_ eq $last) { $counter++; }
		else {
			print "$last,$counter\n";
			undef $last;
			$counter = 0;
		}
	}
	else {
		$last = $_;
		$counter++;
	}
}

__END__

James

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: counters for lines

2004-01-20 Thread Wiggins d Anconia


> 
> I have the following output, and each value that is separated by comma is 
> a variable:
> 
> servera,serverb,109,aix4-r1,server
> servera,serverb,109,aix4-r1,server
> servera,serverb,109,aix4-r1,server
> servera,serverb,109,aix4-r1,server
> servera,serverb,109,aix4-r1,server
> servera,serverb,109,hpux10,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> servera,serverb,109,solaris2,server
> 
> 
> I am trying to set up a counter that would actually output the data to be:
> 
> servera,serverb,109,aix4-r1,server,5
> servera,serverb,109,hpux10,server,1
> servera,serverb,109,solaris2,server,10
> 
> Does anyone any suggestion on how to set up a counter to count the lines 
> until a different line shows up.  I already have the list sorted, so I 
> just need to compare the new string to old string and if they are the
same 
> increase the counter, and if they are different start a new counter.
> 
> 

Use a hash where the key is the line and simply increment the value. 
Does this help?

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




counters for lines

2004-01-20 Thread Anthony J Segelhorst
I have the following output, and each value that is separated by comma is 
a variable:

servera,serverb,109,aix4-r1,server
servera,serverb,109,aix4-r1,server
servera,serverb,109,aix4-r1,server
servera,serverb,109,aix4-r1,server
servera,serverb,109,aix4-r1,server
servera,serverb,109,hpux10,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server
servera,serverb,109,solaris2,server


I am trying to set up a counter that would actually output the data to be:

servera,serverb,109,aix4-r1,server,5
servera,serverb,109,hpux10,server,1
servera,serverb,109,solaris2,server,10

Does anyone any suggestion on how to set up a counter to count the lines 
until a different line shows up.  I already have the list sorted, so I 
just need to compare the new string to old string and if they are the same 
increase the counter, and if they are different start a new counter.


Anthony J Segelhorst
Enterprise Systems Management Team
Phone: 937-495-1876
Email: [EMAIL PROTECTED]


This email has been scanned for all viruses by the MessageLabs SkyScan
service.___

Note:  Please update your email address for this user to reflect the
new MeadWestvaco Corporation.  MeadWestvaco employee email addresses
are in the format of [EMAIL PROTECTED] 

This electronic message contains information from MeadWestvaco
Corporation or subsidiary companies, which may be confidential,
privileged or otherwise protected from disclosure.  The
information is intended to be used solely by the recipient(s)
named.  If you are not an intended recipient, be aware that
any review, disclosure, copying, distribution or use of this
transmission or its contents is prohibited.  If you have
received this transmission in error, please notify MeadWestvaco
immediately at [EMAIL PROTECTED]
___