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
bt707Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
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;
bt707Author Commented:
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,


ozoCommented:
#!/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"
}

Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

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

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

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bt707Author Commented:
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!!!!
bt707Author Commented:
sorry ozo, I put in comments on this but forgot to accept it.

Thanks again!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.