FAQ
Thanks 007....

It worked out of the box.... :)

Cheers,
Parag



On Fri, Nov 13, 2009 at 8:03 PM, 7 wrote:
On Fri, Nov 13, 2009 at 5:07 AM, Parag Kalra wrote:

Hey All,

I have a following a LDIF file to process through Perl -

###############################################################
dn: ou=71404558, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=People, ou=71404558, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=Groups, ou=71404558, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=40208723, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=People, ou=40208723, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=Groups, ou=40208723, ou=Company, ou=Personal, o=paragkalra.com
dn: cn=Mygroup,ou=Groups, ou=40208723, ou=Company, ou=Personal, o=
paragkalra.com
dn: ou=63613012, ou=Company, ou=Personal, o=paragkalra.com
dn: cn=Manager,ou=63613012, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=People, ou=63613012, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=Groups, ou=63613012, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=$%^&?()+-, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=[]{}!@#%*, ou=Company, ou=Personal, o=paragkalra.com
dn: cn=CEO,ou=[]{}!@#%*, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=76884580, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=People, ou=76884580, ou=Company, ou=Personal, o=paragkalra.com
dn: ou=Groups, ou=76884580, ou=Company, ou=Personal, o=paragkalra.com
################################################################

My aim is to extract all those lines starting with the string - 'dn:ou'
and
having only 3 levels of OU heirarchy i.e having the string 'ou=' only 3
times. Also he value of 'ou' can be anything i.e any character (including
special characters) except comman (,).

So to accomplish it I have written following code and is working -

#################################################################
# Author: Parag

my $file = $ARGV[0];

open FILE, $file;

while ( <FILE> ) {
$count = 0;
$_ =~ s/(\s)+//g;
$count++ while $_ =~ /(ou=)/g;
if ( ($count == 3) && ($_ =~ /^(dn:ou)/) ) {
print "$_\n";
}
}

close FILE;

################################################################



But I would like to accomplish it through 1 singe regex like using
following
code -


############################################################
# Author: Parag

my $file = $ARGV[0];

open FILE, $file;

while ( <FILE> ) {
$_ =~ s/(\s)+//g;
if ( $_ =~ /(dn:ou=)([\d\D]+)(ou=Company,ou=Personal,o=paragkalra.com
)/){
print "$_\n";
}
}

close FILE;

############################################################
Any pointers?

Nope. Just trial and error until you come up with an ugly hack. I think
this works:


use strict;
use warnings;
use 5.010;

open (my $INFILE, '<', shift @ARGV);

while (<$INFILE>) {
print if /^dn: ((ou=[^,]+\s*,)\s*){3}[^,]*$/;
}

close $INFILE;

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 5 | next ›
Discussion Overview
groupbeginners @
categoriesperl
postedNov 13, '09 at 12:08p
activeNov 15, '09 at 6:30a
posts5
users3
websiteperl.org

3 users in discussion

7: 2 posts Parag Kalra: 2 posts Shawn H Corey: 1 post

People

Translate

site design / logo © 2022 Grokbase