FW: remove line if field one is duplicate

2007-02-28 Thread Keenan, Greg John \(Greg\)** CTR **
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have to combine several Unix password files and remove any duplicate
> accounts - putting this into LDAP.
>
> I have the following code that will remove any duplicate whole lines
but
> I need to remove lines only if the first field of the password file is
a
> duplicate.

This should work

perl -ne 'print unless $h{(split/:/)[0]}++'


Thanks Jeff & Chas

Both solutions work perfectly.

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




remove line if field one is duplicate

2007-02-28 Thread Keenan, Greg John \(Greg\)** CTR **
Hi,

I have to combine several Unix password files and remove any duplicate
accounts - putting this into LDAP.

I have the following code that will remove any duplicate whole lines but
I need to remove lines only if the first field of the password file is a
duplicate.

-
use strict;
use warnings;

my $passwdfile = "pwcomb";
my %seen = ();
{
   local @ARGV = ($passwdfile);
   local $^I = '.bac'; 
   while(<>){
  $seen{$_}++;
  next if $seen{$_} > 1;
  print;
   }
}
print "finished";
-

Could someone help with a solution to this?

Thanks,
Greg.

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




FW: How to get all the files under the webdir?

2007-02-14 Thread Keenan, Greg John \(Greg\)** CTR **

>Hello lists,
>
>I want to get all the files on some a webdir.For example:
>
>http://www.foo.com/bar/
>
>But that dir has a default page "index.htm".So when I accessed the url
I only got the >default page.
>
>Can you tell me is there a way to fetch all the files in that
dir?Thanks a lot.

Hi,

As Tom mentioned it's not nice if not your own site.

If this is your own site and all you want is to have a listing of files
under http://www.foo.com/bar displayed in your browser remove or rename
the index.htm file.  I'm fairly sure this correct with Apache.  Not sure
with other web servers.


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




RE: installing question

2007-01-18 Thread Keenan, Greg John (Greg)** CTR **

Please take the Gentoo discussion somewhere else. This list is for perl
beginners to get help, not for silly distribution wars. Go play on Slashdot
or something.

On 1/9/07, Arvind Autar <[EMAIL PROTECTED]> wrote:
>
> debian.
>
> Gentoo has a whole history of open source distrobuters who boycot it.
> Check
> out 'gaim' for example.
>
> 2007/1/9, Jorge Almeida <[EMAIL PROTECTED]>:
> >
> > On Tue, 9 Jan 2007, Arvind Autar wrote:
> >
> > > gentoo is a bad distrobution you should remove it and install a 
> > > sane distrobution.
> > >
> > I will follow your suggestion, of course. What brand of Windows do 
> > you favor?
> > --
> > Jorge Almeida
> >
>
>

It hadn't been discussed in 9 days until you bought it up again.

And please bottom post.

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




RE: Work with first x number of elements in array

2006-05-25 Thread Keenan, Greg John (Greg)** CTR **
>Small correction: because of the hyphens those barewords need to be quoted.
>
>my @cfgs = (
>[ Toaster=> 6 ],
>[ 'MFG-UNIX' => 5 ],
>[ 'SYS-UNIX' => 5 ],
>[ 'Amanda-Daily' => 1 ],
>);
>
>my %cfgs = (
>Toaster=> 6,
>'MFG-UNIX' => 5,
>'SYS-UNIX' => 5,
>'Amanda-Daily' => 1,
>);


Yes I picked up on that after I tried to run it. Thanks.

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




RE: Work with first x number of elements in array

2006-05-25 Thread Keenan, Greg John (Greg)** CTR **
>Using an AoA:
>
>for my $cfg ( @cfgs ) {
>my $fileIn = "$cfgDir/$cfg->[0]/tapelist";
>open FILEIN, '<', $fileIn or die "Could not open $fileIn: $!";
>print +( reverse  )[ -$cfg->[1] .. -1 ]; }
>
>Using a hash:
>
>for my $cfg ( keys %cfgs ) {
>my $fileIn = "$cfgDir/$cfg/tapelist";
>open FILEIN, '<', $fileIn or die "Could not open $fileIn: $!";
>print +( reverse  )[ -$cfg{$cfg} .. -1 ]; }
>
>
>Also, if the files are large you can get better efficiency using
>the File::ReadBackwards module.


Thanks for the solutions John, works a treat.  Files are quite small but
will look into File::ReadBackwards

Regards,
Greg.

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




Work with first x number of elements in array

2006-05-25 Thread Keenan, Greg John (Greg)** CTR **
Hi,
 
What is the best way to only work with the first x number of elements in an
array?
 
At the moment this script prints the entire contents of @lines for each
element in @cfgs
 
I would like to restrict this to the number of elements listed in the hash
%numTapes for each element in @cfgs
 
Any suggestions for improving this script much appreciated.
 
Thanks,
Greg.
 
 
--start--
use strict;
use warnings;
 
my $cfgDir = '/amanda/admin/etc/amanda';
my @cfgs = qw(Toaster MFG-UNIX SYS-UNIX Amanda-Daily);
my %numTapes = (
  "$cfgs[0]" => 6,
  "$cfgs[1]" => 5,
  "$cfgs[2]" => 5,
  "$cfgs[3]" => 1,
  );
 
my $cfg;
foreach $cfg (@cfgs) {
my $fileIn="$cfgDir/$cfg/tapelist";
open (FILEIN, "<$fileIn") or die ("Could not open $fileIn: $!");
my @lines = reverse ;
my $line;
foreach $line (@lines) {
print "$line\n";
}
}
--end--


RE: Out of memory! - from CPAN

2006-03-15 Thread Keenan, Greg John (Greg)** CTR **
Hi Jerry,

>The slice that I am building on has 53 Gb of disk space free.

I haven't followed this thread closely so I apologise if any of this has
already been suggested or is not relevant.

Have you checked if any system tables (process, file, inode etc.) are full.
You can also check your kernel parameters e.g. On HP-UX systems maxdsiz,
maxssiz, maxtsiz etc. restrict maximum process size and there are others
that restrict amount of memory a process can use.

The point I'm trying to make is you can have all the physical disk/memory
you like but if per process kernel restrictions are in place then all those
resources may not be available.

Check your syslogs and dmesg for entries when you get the "out of memory"
errors.

Good luck,
Greg.

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




RE: num to alpha

2006-02-27 Thread Keenan, Greg John (Greg)** CTR **
>> I know John Krahn is a fan of %map.

>I am?

>> He has advised me on using it before.
>> 
>> Just wondering if there was any reason he chose to use %convert 
>> instead in his example above.

>%map and %convert are just hash names, you can use any name that you want.


Sorry - my mistake.

Still trying to get the hang of perl and I've totally confused a few things.
Back to the books for me!

Cheers,
Greg.

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




RE: num to alpha

2006-02-27 Thread Keenan, Greg John (Greg)** CTR **
>
>my %convert = qw[ 1 a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9 i 10 j 11 k 12 l 13 m
14 >n
>15 o 16 p 17 q 18 r 19 s 20 t 21 u 22 v 23 w 24 x 25 y 26 z ];
>

Hi,

I know John Krahn is a fan of %map.  He has advised me on using it before.

Just wondering if there was any reason he chose to use %convert instead in
his example above.

Cheers,
Greg.

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




Regex - find chars between ()

2005-09-11 Thread Keenan, Greg John (Greg)** CTR **
Hi,
 
Have a file like:
 
meteor(L, 4) (G,24)
rocket(J,19) (D,35)
aulan (E,28) (E, 2)
aupbx (B,32) (O,10)
 
And I need to work with the chars between the brackets after I've found the
string on the left e.g. if my $host variable matches rocket then I need to
get J and 19 and D and 35 into an array or their own seperate variables.
 
I have been going around in circles with the regex.  I have tried escaping
the round brackets with \, anchoring the string to the end with \z and a
multitude of other combos of \D \d \w . \s etc.
 
Note that some coordinates have two digits and others single digit with
whitespace before it.
 
#StartCode
use strict;
use warnings;
use diagnostics;
 
my $host = $ARGV[0];
my $dirRoot = "/gjkeenan/G7";
my $fileG7 = "$dirRoot/G7";
my $filePW = "$dirRoot/PW";
 
open(PWFILE, "$filePW")
  || die "Can't open $filePW: $!";
while () {
  if (/$host/) {
my @c = /(\D,\d\d)\s(\D,\d\d)/;
  }
}
close(PWFILE);
...do something with $c[0] $c[1] $c[2] $c[3]...
#EndCode
 
 
Really appreciate some pointers.
Regards, Greg


RE: Read txt file and use each line as regex and output matches t o file.

2005-09-11 Thread Keenan, Greg John (Greg)** CTR **

>Thanks for the pointers I have made your recommended modifications, as you
>can see I'm new to this, much appreciated. :-)
>
>The script as it stands is very inefficient because of the way I have done
>it, you mentioned saving the matches or IP's in a hash how would I go about
>doing this if you dont mind me asking?
>
>John W. Krahn wrote:
>
>> I don't understand why you are saying that the append option does not 
>> workcorrectly. What exactly are you trying to accomplish?
>>
>Hi John!
>
>Thanks,
>The append option works correctly the first time and then continues
>to append to the file every time I run it.0
>So in effect I'm getting the same log entries appear in the dump file
>($date-$ip.log).
>I will want to run the script every (x) seconds and dump each
>router/firewall log to its own log file for further processing
>, if I could get it to check from the last point in the
> $log_file even better but thats for a later mission.


There is a solution, "Trailing a Growing File", in the Perl Cookbook that I
have used before that may solve your problem.

I ran my script from inittab so it respawned if it died and it checks any
new data written to a log file.  If a certain string is found it did some
processing.  I don't have my script anymore but this is the excert from the
Cookbook:

$naptime = 1;
use IO::Handle;
open (LOGFILE, "/tmp/logfile") or die "can't open /tmp/logfile: $!";
for (;;) {
while () { check for your IP and do something }
sleep $naptime;
LOGFILE->clearerr();# clear stdio error flag
}




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




RE: 2-way lookup

2005-09-08 Thread Keenan, Greg John (Greg)** CTR **
 -Original Message-
>> Hi,
>
>Hello,
>
>> I have a file like:
>>  
>>   A   B   C
>> 1aa11bb11cc11
>> 2aa22bb22cc22
>> 3aa33bb33cc33
>> 4aa44bb44cc44
>>  
>> I have two sets of coordinates like (A2, C1) and I need to join them 
>> together like aa22cc11
>>  
>> I am going to pull the relevent line for the first coordinate into an 
>> array then pull out the relevant element then repeat the steps for the 
>> second coordinate e.g.
>>  
>> @lines = ;
>> @line = $lines[3];
>> $coordData1 = $line[1];
>> @line = $lines[2];
>> $coordData2 = $line[3];
>> ...do something with $coordData1 & $coordData2
>>  
>> I'm hoping for a better way and I'm looking for suggestions.
>
>You may want something like:
>
>my @lines = map [ split ], ;
>...do something with $lines[1][0] & $lines[0][1]


Thanks John & Jeff for the suggestions.  I've gone with John's solution.
Looks like I need to read up on the map function.

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




2-way lookup

2005-09-08 Thread Keenan, Greg John (Greg)** CTR **
Hi,
 
I have a file like:
 
  A   B   C
1aa11bb11cc11
2aa22bb22cc22
3aa33bb33cc33
4aa44bb44cc44
 
I have two sets of coordinates like (A2, C1) and I need to join them
together like aa22cc11
 
I am going to pull the relevent line for the first coordinate into an array
then pull out the relevant element then repeat the steps for the second
coordinate e.g.
 
@lines = ;
@line = $lines[3];
$coordData1 = $line[1];
@line = $lines[2];
$coordData2 = $line[3];
...do something with $coordData1 & $coordData2
 
I'm hoping for a better way and I'm looking for suggestions.
 
Thanks for your time.

Greg Keenan 
Lucent Technologies * 
Level 1, 68 Waterloo Road 
North Ryde NSW 2113 
Australia 
* +61 2 9491 6898 
* [EMAIL PROTECTED] 

 


RE: regex - no field seperator

2005-08-18 Thread Keenan, Greg John (Greg)** CTR **
 -Original Message-
From: John W. Krahn [mailto:[EMAIL PROTECTED] 
Sent: Friday, 19 August 2005 10:26 AM
To: Perl Beginners
Subject: Re: regex - no field seperator

Keenan, Greg John (Greg)** CTR ** wrote:
>>From: Wagner, David --- Senior Programmer Analyst --- WGO
>>
>>Keenan, Greg John (Greg)** CTR ** wrote:
>>>
>>>I have the following data that I'm trying to parse into an array. 
>>>There are 19 fields but with hosts 5 & 6 fields 6 & 7 do not have any 
>>>space between them.  This is how I get it from the OS and have no 
>>>control over it.
>>>
>>>The maximum length for field 6 is 7 chars and field 7 is 6 chars.
>>>
>>>200508171648 host1.dom.com 0 0 14 2166 623 8 4 12 0 0 0 35 131 14 0 0 
>>>100
>>>200508171648 host2.dom.com 0 0 0 265 7563 5 3 8 0 0 0 34 66 7 0 0 100
>>>200508171648 host3.dom.com 0 0 0 461 8112 4 0 6 0 0 0 53 84 9 0 0 100
>>>200508171648 host4.dom.com 0 0 0 46 9468 5 3 9 0 0 0 39 75 8 0 2 98
>>>200508171648 host5.dom.com 0 1 0 7008342480 3 0 0 0 0 0 0 41 8 0 2 98
>>>200508171648 host6.dom.com 0 1 0 8936445548 3 0 0 0 0 0 0 14 5 0 0 
>>>100
>>>
>>>I have tried the following, and several other combos, with no luck. 
>>>It matches the first 4 lines but fails for the last 2 because they 
>>>appear to have only 18 fields I assume.
>>>@oput = /(\d+) (.+\..+\..+) (\d+) (\d+) (\d+) (\d{2,7}) (\d{2,6})
>>>(\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) 
>>>(\d+)/;
>>>
>>  You are working much too hard to capture the data. Use split like:
>>
>>  @oput = split (/\s+/,$_);
>>You say it is a total of 13 characters, but in this case you have 10 
>>characters. How do you identify which field is full? Once you do that 
>>then >the ability to get it can be done. But you have to first 
>>identify how to know out say in this case the 10 chaacters what the 
>>proper split is?
> 
> Fields 6 & 7 could be a minimum of 2 chars or 7 & 6 chars respectively 
> but the only time fields 6 & 7 merge is if field 7 has reached its 
> maximum length of 6 chars.

Well then, that should be easy enough.  :-)


while (  ) {

my @oput = split;

if ( @oput == 18 ) {
splice @oput, 5, 1, $oput[ 5 ] =~ /(.+)(.{6})/;
}
elsif ( @oput != 19 ) {
warn "Error in $file line $. - wrong number of input fields.\n";
next;
}

do_something_with( @oput );
}


Thanks to David & John for their excellent solutions.  I've learnt a little
bit more about perl & regexs over the last few days.

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




RE: regex - no field seperator

2005-08-18 Thread Keenan, Greg John (Greg)** CTR **
-Original Message-
>From: Wagner, David --- Senior Programmer Analyst --- WGO
>[mailto:[EMAIL PROTECTED] 
>Sent: Friday, 19 August 2005 3:21 AM
>To: Keenan, Greg John (Greg)** CTR **; beginners@perl.org
>Subject: RE: regex - no field seperator
>
>Keenan, Greg John (Greg)** CTR ** wrote:
>> Hi,
>> 
>> I have the following data that I'm trying to parse into an array. 
>> There are 19 fields but with hosts 5 & 6 fields 6 & 7 do not have any 
>> space between them.  This is how I get it from the OS and have no 
>> control over it.
>> 
>> The maximum length for field 6 is 7 chars and field 7 is 6 chars.
>> 
>> 200508171648 host1.dom.com 0 0 14 2166 623 8 4 12 0 0 0 35 131 14 0 0 
>> 100
>> 200508171648 host2.dom.com 0 0 0 265 7563 5 3 8 0 0 0 34 66 7 0 0 100
>> 200508171648 host3.dom.com 0 0 0 461 8112 4 0 6 0 0 0 53 84 9 0 0 100
>> 200508171648 host4.dom.com 0 0 0 46 9468 5 3 9 0 0 0 39 75 8 0 2 98
>> 200508171648 host5.dom.com 0 1 0 7008342480 3 0 0 0 0 0 0 41 8 0 2 98
>> 200508171648 host6.dom.com 0 1 0 8936445548 3 0 0 0 0 0 0 14 5 0 0 100
>> 
>> I have tried the following, and several other combos, with no luck. 
>> It matches the first 4 lines but fails for the last 2 because they 
>> appear to have only 18 fields I assume.
>> @oput = /(\d+) (.+\..+\..+) (\d+) (\d+) (\d+) (\d{2,7}) (\d{2,6})
>> (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) 
>> (\d+)/;
>> 
>   You are working much too hard to capture the data. Use split like:
>
>   @oput = split (/\s+/,$_);
>You say it is a total of 13 characters, but in this case you have 10
>characters. How do you identify which field is full? Once you do that
>then >the ability to get it can be done. But you have to first
>identify how to know out say in this case the 10 chaacters what
>the proper split is?

Fields 6 & 7 could be a minimum of 2 chars or 7 & 6 chars respectively but
the only time fields 6 & 7 merge is if field 7 has reached its maximum
length of 6 chars.

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




regex - no field seperator

2005-08-17 Thread Keenan, Greg John (Greg)** CTR **
Hi,
 
I have the following data that I'm trying to parse into an array.  There are
19 fields but with hosts 5 & 6 fields 6 & 7 do not have any space between
them.  This is how I get it from the OS and have no control over it.
 
The maximum length for field 6 is 7 chars and field 7 is 6 chars.
 
200508171648 host1.dom.com 0 0 14 2166 623 8 4 12 0 0 0 35 131 14 0 0 100
200508171648 host2.dom.com 0 0 0 265 7563 5 3 8 0 0 0 34 66 7 0 0 100
200508171648 host3.dom.com 0 0 0 461 8112 4 0 6 0 0 0 53 84 9 0 0 100
200508171648 host4.dom.com 0 0 0 46 9468 5 3 9 0 0 0 39 75 8 0 2 98
200508171648 host5.dom.com 0 1 0 7008342480 3 0 0 0 0 0 0 41 8 0 2 98
200508171648 host6.dom.com 0 1 0 8936445548 3 0 0 0 0 0 0 14 5 0 0 100
 
I have tried the following, and several other combos, with no luck.  It
matches the first 4 lines but fails for the last 2 because they appear to
have only 18 fields I assume.
@oput = /(\d+) (.+\..+\..+) (\d+) (\d+) (\d+) (\d{2,7}) (\d{2,6}) (\d+)
(\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+)/;
 
Can someone point me in the right direction please?
 
Thanks Greg.


FW: Find string ending with %

2005-08-16 Thread Keenan, Greg John (Greg)** CTR **
-Original Message-
From: John W. Krahn [mailto:[EMAIL PROTECTED] 

while() {
  my @oput2 = /(\d+)%/ or next;
  print "XXX @oput2 XXX\n";
}



Thanks John, that's solved it.  I'll read up on next.

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




Find string ending with %

2005-08-16 Thread Keenan, Greg John (Greg)** CTR **
Hi,

Need some help with a regex please.

I need to search a file for every instance of a string that ends with %.
Think output from the df command.  I need the 1, 2 or 3 digits before the %
passed into the array.

Code:
#!/usr/bin/perl
use warnings;
use strict;

my $outfile2 = "XXX.dat";
open(DATA2, "< $outfile2") || die "Can't open $outfile2: $!\n";
while() {
  my @oput2 = /\b([0-9]+)%/;
  print "XXX @oput2 XXX\n";
}
close(DATA2);

It is kind of working but I pick up stuff I don't want e.g:

Input data(XXX.dat):
head
123 123 111% 123
456 22% 456 456 456
789
tail

Output data:
XXX  XXX
XXX 111 XXX
XXX 22 XXX
XXX  XXX
XXX  XXX

How do I tell it not to process every line in the file, just the lines that
contain the relevant string?

Thanks,
Greg Keenan
Lucent Technologies * 
Level 1, 68 Waterloo Road
North Ryde NSW 2113
Australia
* +61 2 9491 6898 
* [EMAIL PROTECTED] 




system v backticks

2005-07-27 Thread Keenan, Greg John (Greg)** CTR **
Hi,

Can someone explain the difference between backticks and system when
evaluated in this if statement:


sub getDate {
 print "start date\n";
 if ( system("/bin/date") ) {
   print "can't get date\n";
   exit(2);
 }
 print "finish date\n";
}

Returns the following:

start date
Thu Jul 28 12:13:59 EST 2005
finish date



While this:

sub getDate {
 print "start date\n";
 if ( `/bin/date` ) {
   print "can't get date\n";
   exit(2);
 }
 print "finish date\n";
}

Returns this:

start date
can't get date


O Lucent Technologies
Level 1, 68 Waterloo Rd.
North Ryde NSW 2113
Australia
Tel:+61 (0)2 9491 6898
Mob:+61 (0)434 127 545


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