bt707
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=organizational Person
objectClass=inetorgperson
objectClass=icscalendaruse r
cn=James Smith 358963
givenName=James
sn=Smith
displayName=James Smith
mail=JSmith@city1.oilfield .abc.com
uid=JSmith03
description=almudena-20051 207
cn=Mary Jones 356156,ou=contractor,o=abc ,c=AN
employeeType=contractor
objectClass=top
objectClass=person
objectClass=organizational Person
objectClass=inetorgperson
objectClass=icscalendaruse r
cn=Mary Jones 356156
icsCalendarOwned=MaryJ01$M ary Jones
givenName=Mary
sn=Jones
displayName=Mary Jones
mail=MaryJ@city2.abc.com
uid=MaryJ01
description=siti-20051110
icsExtendedUserPrefs=ceInt erval=PT0H 30M
icsExtendedUserPrefs=ceExc ludeSatSun =1
icsExtendedUserPrefs=ceGro upInviteAl l=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
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
employeeType=contractor
objectClass=top
objectClass=person
objectClass=organizational
objectClass=inetorgperson
objectClass=icscalendaruse
cn=James Smith 358963
givenName=James
sn=Smith
displayName=James Smith
mail=JSmith@city1.oilfield
uid=JSmith03
description=almudena-20051
cn=Mary Jones 356156,ou=contractor,o=abc
employeeType=contractor
objectClass=top
objectClass=person
objectClass=organizational
objectClass=inetorgperson
objectClass=icscalendaruse
cn=Mary Jones 356156
icsCalendarOwned=MaryJ01$M
givenName=Mary
sn=Jones
displayName=Mary Jones
mail=MaryJ@city2.abc.com
uid=MaryJ01
description=siti-20051110
icsExtendedUserPrefs=ceInt
icsExtendedUserPrefs=ceExc
icsExtendedUserPrefs=ceGro
__________________________
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.
Mary Jones MaryJ01 MaryJ@city2.abc.com
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,
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=(
($sn)=/^sn=(.*)/m;
($uid)=/^uid=(.*)/m;
($mail)=/^mail=(.*)/m;
while(<>) if {$givenName,$sn,$uid,$mail
}
print join("\t",$givenName,$sn,$
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"
}
use strict ;
use warnings ;
local $/=',o=abc,';
while(<>){
($givenName)=/^givenName=(
($sn)=/^sn=(.*)/m;
($uid)=/^uid=(.*)/m;
($mail)=/^mail=(.*)/m;
print join("\t",$givenName,$sn,$
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!!!!
just trying to learn this, still not doing to good but this should help out a lot.
Thanks again, have a Great New Year!!!!
ASKER
sorry ozo, I put in comments on this but forgot to accept it.
Thanks again!!
Thanks again!!
then
($givenName)=/^givenName=(
($sn)=/^sn=(.*)/m;
($uid)=/^uid=(.*)/m;
($mail)=/^mail=(.*)/m;