Link to home
Start Free TrialLog in
Avatar of bt707
bt707Flag for United States of America

asked on

help with perl

Just trying to learn a few things here.

I have a file that contains many user records they are not seperated and don't always end with
the same attribute, but they do always start with "cn=" attribute however there is two cn= lines but
the one that starts the record always has o=abc in it.

____________________________________________________________
cn=James Smith  358963,ou=contractor,o=abc,c=AN
employeeType=contractor
objectClass=top
objectClass=person
objectClass=organizationalPerson
objectClass=inetorgperson
objectClass=icscalendaruser
cn=James Smith  358963
givenName=James
sn=Smith
displayName=James Smith
mail=JSmith@city1.oilfield.abc.com
uid=JSmith03
description=almudena-20051207
cn=Mary Jones  356156,ou=contractor,o=abc,c=AN
employeeType=contractor
objectClass=top
objectClass=person
objectClass=organizationalPerson
objectClass=inetorgperson
objectClass=icscalendaruser
cn=Mary Jones  356156
icsCalendarOwned=MaryJ01$Mary Jones
givenName=Mary
sn=Jones
displayName=Mary Jones
mail=MaryJ@city2.abc.com
uid=MaryJ01
description=siti-20051110
icsExtendedUserPrefs=ceInterval=PT0H30M
icsExtendedUserPrefs=ceExcludeSatSun=1
icsExtendedUserPrefs=ceGroupInviteAll=1
____________________________________________________________

What I'm trying to learn here is how to:

set a $/ seperator for this first line to seperate the records then
pull out a few of the lines to make a spead sheet something like:

print join("\t",qw/givenName sn uid mail/),"\n";

So it will print out from these two records like this:

givenName   sn              uid               mail
James             Smith   JSmith03      JSmith@city1.oilfield.abc.com
Mary              Jones    MaryJ01       MaryJ@city2.abc.com
Avatar of ozo
ozo
Flag of United States of America image

If there are no other ,o=abc, in the record, you might set $/=',o=abc,';

then
($givenName)=/^givenName=(.*)/m;
($sn)=/^sn=(.*)/m;
($uid)=/^uid=(.*)/m;
($mail)=/^mail=(.*)/m;
Avatar of bt707

ASKER

ozo,

There is no other o=abc in each record so that will work.

I"m trying something like this but obviously it just looks like a big mess.


#!/usr/bin/perl
use strict ;
use warnings ;
local $/=',o=abc,';

($givenName)=/^givenName=(.*)/m;
($sn)=/^sn=(.*)/m;
($uid)=/^uid=(.*)/m;
($mail)=/^mail=(.*)/m;

while(<>) if {$givenName,$sn,$uid,$mail
}

print join("\t",$givenName,$sn,$uid,$mail),"\n"


Thanks,


#!/usr/bin/perl
use strict ;
use warnings ;
local $/=',o=abc,';

while(<>){
($givenName)=/^givenName=(.*)/m;
($sn)=/^sn=(.*)/m;
($uid)=/^uid=(.*)/m;
($mail)=/^mail=(.*)/m;

print join("\t",$givenName,$sn,$uid,$mail),"\n"
}

ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bt707

ASKER

Thanks ozo,

just trying to learn this, still not doing to good but this should help out a lot.

Thanks again, have a Great New Year!!!!
Avatar of bt707

ASKER

sorry ozo, I put in comments on this but forgot to accept it.

Thanks again!!