jzelkowsz has asked for the wisdom of the Perl Monks concerning the following question:
I have two files. One is an HR record of the user's values; the other is a network export of their attributes. I am trying to compare the two files and find the differences attribute by attribute. The sole reliable key is the samaccountname which is present and consistent in every record. I am trying to produce a file like this:
Where each line of the produced file holds the samaccountname,attribute that is incorrect, and the correct value of the attribute from the HR record. One mistake per line.barsu991,title,Director of Cooks zingk072,symphonyemployeetype,IKP zingk072,employeenumber,zingk072 zingk072,manager,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net"
I have tried to do this with loops like below but the best I get is a comparison with the last line and not all of them.
open(HR, "<hr.txt") || die "can't open hr"; open(AD, "<ad.txt") || die "can't open ad"; open(COMMAND, ">com.txt") || die "can't open com.txt"; while(<HR>) { ($samaccountnameHR,$givennameHR,$snHR,$initialsHR, $employeenumberHR,$symphonyemployeetypeHR,$mailHR, $titleHR,$departmentHR,$companyHR,$lHR, $physicaldeliveryofficeHR,$streetaddressHR,$stHR, $postalcodeHR,$telephonenumberHR,$managerHR)=split(/,$/); while(<AD>) { ($samaccountnameAD,$givennameAD,$snAD,$initialsAD,$employeenumberAD, $symphonyemployeetypeAD,$mailAD, $titleAD,$departmentAD,$companyAD, $lAD,$physicaldeliveryofficeAD,$streetaddressAD,$stAD,$postalcodeAD, $telephonenumberAD,$managerAD)=split(/,$/); if ($employeenumberHR != $employeenumberAD) { print "$samaccountnameHR $samaccountnameAD\n"; } } }
HR Data: samaccountname,givenname,sn,initials,employeenumber, symphonyemployeetype,mail,title,department,company,l, physicaldeliveryoffice,streetaddress,st,postalcode, telephonenumber,manager barsu991,Uttiam,Barski,K,20114598,IKP, Uttiam.Barski@pulse.org,Director of Cooks,Day Kitchen, MILIFO,Alpena,Kitchen of the World,400 Baker,WI,50987, 555-555-5555,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" walkl003,Lreblemet,Walker,J,20178941,IKP, Lreblemet.Walker@pulse.org,Head Cook,Day Kitchen,MILIFO,Alpena, Kitchen of the World,400 Baker,WI,50987,555-555-5551, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" karss001,Sovyetk,Karsten,Y,20146598,IKP,Sovyetk.Karsten@pulse.org, Dishwasher,Day Kitchen,MILIFO,Alpena,Kitchen of the World, 205 Willy B. Temple,WI,50987,, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" zingk072,Kovon,Zingerman,K,20113578,IKP,Kovon.Zingerman@pulse.org, Baker,Day Kitchen,MILIFO,Alpena,Kitchen of the World, 205 Willy B. Temple,WI,50987,, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" peizs194,Synthia,Smite,B,20134743,IKP,Synthia.Peizer@pulse.org, Broiler Man,Day Kitchen,MILIFO,Alpena, Kitchen of the World,205 Willy B. Temple, WI,50987,,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" hutcy231,Yello,Hutchinson,W,20145712,IKP, Yello Hutchinson,@pulse.org, Bottle Washer,Day Kitchen,MILIFO,Alpena, Kitchen of the World,400 Baker,WI,50987, ,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" haserz221,Zebediah,Haserkrilk,L,20125471,IKP, Zebediah.Haserkrilk@kit.org, Purchaser,Day Kitchen,MILIFO,Alpena, Kitchen of the World,400 Baker,WI,50987, ,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net"
AD data: samaccountname,givenname,sn,initials,employeenumber, symphonyemployeetype,mail,title,department,company,l, physicaldeliveryoffice,streetaddress,st,postalcode, telephonenumber,manager barsu991,Uttiam,Barski,K,20114598,IKP, William.Barski@pulse.org,Chief of Cooks,Day Kitchen, MILIFO,Alpena,Kitchen of the World,400 Baker,WI,50987, 555-555-5555, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" walkl003,Larry,Walker,J,,IKP,Larry.Walker@pulse.org, Cook,Day Kitchen,MILIFO,Alpena,Kitchen of the World, 400 Baker,WI,50987,555-555-5551, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" karss001,Steven,Karsten,Y,20146598,IKP, Steven.Karsten@pulse.org,Dishw,Day Kitchen,MILIFO, Alpena,Sully's Kitchen,48720 Belcard,IL,34567,, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" zingk072,Kevin,Zingerman,K,,,Kevin.Zingerman@pulse.org, Baker,Day Kitchen,MILIFO,Alpena,Kitchen of the World, 205 Willy B. Temple,WI,50987,, peizs194,Samantha,Smith,B,20134743,IKP, Samantha.Smith@pulse.org,"Man, Broiler",Day Kitchen, MILIFO,Alpena,Kitchen of the World,205 Willy B. Temple, WI,50987,,"cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" hutcy231,Yaren,Hutchinson,W,20145712,IKP, Yaren Hutchinson,@pulse.org,Bottle Washer,Day Kitchen,MILIFO, Alpena,Kitchen of the World,400 Baker,WI,50987,, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net" haserz221,Zebediah,Hasermann,L,,IKP, Zebediah.Haserman@pulse.org,Purchaser,Day Kitchen,MILIFO, Alpena,Kitchen of the World,400 Baker,WI,50987,555-555-5555, "cn=manager1,ou=users,ou=Kitchen,dc=Kitchen,dc=net"
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Comparing two files line by line and exporting the differences from the first file
by Tux (Canon) on Jul 23, 2018 at 12:04 UTC | |
Re: Comparing two files line by line and exporting the differences from the first file
by kcott (Archbishop) on Jul 23, 2018 at 10:58 UTC | |
Re: Comparing two files line by line and exporting the differences from the first file
by AnomalousMonk (Archbishop) on Jul 23, 2018 at 16:06 UTC | |
Re: Comparing two files line by line and exporting the differences from the first file
by Cristoforo (Curate) on Jul 23, 2018 at 02:58 UTC | |
by AnomalousMonk (Archbishop) on Jul 23, 2018 at 03:18 UTC |